[llvm] [RegAlloc] Account for use availability when applying rematerializable weight discount (PR #159180)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 22 04:49:49 PDT 2025


================
@@ -124,6 +127,75 @@ bool VirtRegAuxInfo::isRematerializable(const LiveInterval &LI,
 
     if (!TII.isTriviallyReMaterializable(*MI))
       return false;
+
+    VNIDefs[OrigVNI->id] = MI;
+  }
+
+  // If MI has register uses, it will only be rematerializable if its uses are
+  // also live at the indices it will be rematerialized at.
+  for (MachineOperand &Use : MRI.use_nodbg_operands(LI.reg())) {
+    if (Use.isUndef())
+      continue;
----------------
lukel97 wrote:

Thanks, TIL.

> A sub-register def implicitly reads the other parts of the register being redefined unless the <undef> flag is set.

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


More information about the llvm-commits mailing list