[llvm] [RegisterCoalescer] Mark implicit-defs of super-registers as dead in remat (PR #159110)

Benjamin Maxwell via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 24 05:12:18 PDT 2025


================
@@ -1640,9 +1641,32 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
     // been asked for. If so it must implicitly define the whole thing.
     assert(DstReg.isPhysical() &&
            "Only expect virtual or physical registers in remat");
+
+    // When we're rematerializing into a not-quite-right register we already add
+    // the real definition as an implicit-def, but we should also be marking the
+    // "official" register as dead, since nothing else is going to use it as a
+    // result of this remat. Not doing this can affect pressure tracking.
     NewMI.getOperand(0).setIsDead(true);
----------------
MacDue wrote:

Not really. `MachineInstr::addRegisterDead` seems to have a definition of "dead" that conflicts with this code. Here, a super-register `dead` and a sub-register defined means "everything except the sub-register is dead" (which is required for pressure tracking), but `addRegisterDead` seems to disagree, as `addRegisterDead($rax)` will turn:

`dead $eax = FOO implicit-def $rax` into  `$eax = FOO implicit-def dead $rax` (which implies it thinks "all sub-registers covered by a dead register are dead").


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


More information about the llvm-commits mailing list