[llvm] [RegAlloc][X86] Rematerialization of instructions with physical register (PR #198853)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 3 10:49:30 PDT 2026


================
@@ -146,17 +152,44 @@ bool VirtRegAuxInfo::isRematerializable(const LiveInterval &LI,
   return true;
 }
 
-bool VirtRegAuxInfo::allUsesAvailableAt(const MachineInstr *MI,
+bool VirtRegAuxInfo::allUsesAvailableAt(const MachineInstr *OrigMI,
                                         SlotIndex UseIdx,
                                         const LiveIntervals &LIS,
                                         const MachineRegisterInfo &MRI,
                                         const TargetInstrInfo &TII) {
-  SlotIndex OrigIdx = LIS.getInstructionIndex(*MI).getRegSlot(true);
+  SlotIndex OrigIdx = LIS.getInstructionIndex(*OrigMI).getRegSlot(true);
+  auto MBB = LIS.getMBBFromIndex(UseIdx);
+  MachineInstr *UseMI = LIS.getInstructionFromIndex(UseIdx);
+  MachineBasicBlock::iterator UseIt = UseMI;
+  if (!UseMI) {
+    if (MBB->empty() ||
+        UseIdx < LIS.getInstructionIndex(*MBB->begin()).getBaseIndex())
+      UseIt = MBB->begin();
+    else {
+      UseIt = MBB->end();
+    }
----------------
weiguozhi wrote:

The purpose of this code snippet is to find a valid instruction iterator UseIt, it is used later to check if a physical register is dead at this position. For an empty basic block, the only valid instruction iterator is begin().


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


More information about the llvm-commits mailing list