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

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 22 04:47:13 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;
----------------
arsenm wrote:

This will miss uses in defs, this should use reg_nodbg_operands and check MO.readsReg 

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


More information about the llvm-commits mailing list