[llvm] [RegisterCoalescer] Avoid redundant rematerialization when def has intervening store uses (PR #212232)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 30 05:59:05 PDT 2026
================
@@ -1328,6 +1328,58 @@ bool RegisterCoalescer::reMaterializeDef(const CoalescerPair &CP,
if (!TII->isReMaterializable(*DefMI))
return false;
+ if (DstReg.isPhysical() && DefMI->getParent() == CopyMI->getParent()) {
+ // Check if DstReg is used by a return instruction immediately after CopyMI,
+ // with no intervening redefinition or tail call. In this case, remating a
+ // trivial def (e.g., LI 0) when SrcReg has store uses between DefMI and
+ // CopyMI would be harmful: DefMI cannot be deleted (still used by stores),
+ // so remat would introduce a redundant instruction.
+ MachineBasicBlock *MBB = CopyMI->getParent();
+ bool RedefinedAfterCopy = false;
+ bool HasMusttail = false;
+ MachineInstr *Ret = nullptr;
+ for (auto I = std::next(CopyMI->getIterator()); I != MBB->end(); ++I) {
----------------
arsenm wrote:
This shouldn't really need a scan through the function. This should stick to computing information based on LiveIntervals
https://github.com/llvm/llvm-project/pull/212232
More information about the llvm-commits
mailing list