[llvm] [RegisterCoalescer] Remove unneeded definesFullReg check (PR #178241)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 27 07:56:38 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-regalloc

Author: Jay Foad (jayfoad)

<details>
<summary>Changes</summary>

An equivalent check is already done inside
TargetInstrInfo::isReMaterializable.


---
Full diff: https://github.com/llvm/llvm-project/pull/178241.diff


1 Files Affected:

- (modified) llvm/lib/CodeGen/RegisterCoalescer.cpp (-18) 


``````````diff
diff --git a/llvm/lib/CodeGen/RegisterCoalescer.cpp b/llvm/lib/CodeGen/RegisterCoalescer.cpp
index 971813d1c22a7..527ecca6eab47 100644
--- a/llvm/lib/CodeGen/RegisterCoalescer.cpp
+++ b/llvm/lib/CodeGen/RegisterCoalescer.cpp
@@ -1288,22 +1288,6 @@ bool RegisterCoalescer::removePartialRedundancy(const CoalescerPair &CP,
   return true;
 }
 
-/// Returns true if @p MI defines the full vreg @p Reg, as opposed to just
-/// defining a subregister.
-static bool definesFullReg(const MachineInstr &MI, Register Reg) {
-  assert(!Reg.isPhysical() && "This code cannot handle physreg aliasing");
-
-  for (const MachineOperand &Op : MI.all_defs()) {
-    if (Op.getReg() != Reg)
-      continue;
-    // Return true if we define the full register or don't care about the value
-    // inside other subregisters.
-    if (Op.getSubReg() == 0 || Op.isUndef())
-      return true;
-  }
-  return false;
-}
-
 bool RegisterCoalescer::reMaterializeDef(const CoalescerPair &CP,
                                          MachineInstr *CopyMI,
                                          bool &IsDefCopy) {
@@ -1335,8 +1319,6 @@ bool RegisterCoalescer::reMaterializeDef(const CoalescerPair &CP,
   if (!TII->isReMaterializable(*DefMI))
     return false;
 
-  if (!definesFullReg(*DefMI, SrcReg))
-    return false;
   bool SawStore = false;
   if (!DefMI->isSafeToMove(SawStore))
     return false;

``````````

</details>


https://github.com/llvm/llvm-project/pull/178241


More information about the llvm-commits mailing list