[llvm] [RegAlloc][X86] Rematerialization of instructions with physical register (PR #198853)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 13 05:35:35 PDT 2026
================
@@ -146,17 +146,43 @@ 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();
+ }
+ }
UseIdx = std::max(UseIdx, UseIdx.getRegSlot(true));
- for (const MachineOperand &MO : MI->operands()) {
- if (!MO.isReg() || !MO.getReg() || !MO.readsReg())
+
+ for (const MachineOperand &MO : OrigMI->operands()) {
+ if (!MO.isReg() || !MO.getReg())
continue;
+ if (!MO.readsReg()) {
+ if (MO.getReg().isVirtual())
+ continue;
+ // A physical register is defined here, and we allow rematerialization of
+ // an instruction with physical register definition, it must be dead at
+ // this position.
+ const TargetRegisterInfo *TRI = MRI.getTargetRegisterInfo();
+ if (MBB->computeRegisterLiveness(TRI, MO.getReg(), UseIt) ==
----------------
arsenm wrote:
You shouldn't be using computeRegisterLiveness in RA code, you have the full LiveIntervals available
https://github.com/llvm/llvm-project/pull/198853
More information about the llvm-commits
mailing list