[llvm] [1/2][AMDGPU] Fixed crash due to virtual register defs not dominating uses (PR #198472)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 3 05:53:43 PDT 2026
================
@@ -529,6 +562,48 @@ void AMDGPURewriteAGPRCopyMFMAImpl::eliminateSpillsOfReassignedVGPRs() const {
if (SpillReferences == SpillSlotReferences.end())
continue;
+ // For each spill reload, every path from entry to the reload must pass
+ // through at least one spill store to the same stack slot.
+ SmallPtrSet<MachineBasicBlock *, 4> StoreBlocks;
+ for (MachineInstr *MI : SpillReferences->second) {
+ if (MI->mayStore() && MDT.isReachableFromEntry(MI->getParent()))
+ StoreBlocks.insert(MI->getParent());
+ }
+
+ if (StoreBlocks.empty()) {
+ LLVM_DEBUG(dbgs() << "Skipping " << printReg(Slot, &TRI)
+ << ": no reachable stores\n");
+ continue;
+ }
+
+ // Compute blocks reachable from entry without passing through a store
+ // block.
+ MachineBasicBlock &EntryMBB = MF.front();
+ SmallPtrSet<MachineBasicBlock *, 16> StoreFreeReachable = {&EntryMBB};
+ SmallVector<MachineBasicBlock *, 16> Worklist = {&EntryMBB};
+
+ while (!Worklist.empty()) {
+ MachineBasicBlock *MBB = Worklist.pop_back_val();
+ if (StoreBlocks.contains(MBB))
+ continue;
+
+ for (MachineBasicBlock *Succ : MBB->successors()) {
+ if (StoreFreeReachable.insert(Succ).second)
+ Worklist.push_back(Succ);
+ }
+ }
+
+ // Every reachable reload must be jointly dominated by the slot's stores.
+ if (!llvm::all_of(SpillReferences->second, [&](const MachineInstr *MI) {
+ return !MI->mayLoad() ||
----------------
arsenm wrote:
Could probably tighten this condition to specifically spill opcodes
https://github.com/llvm/llvm-project/pull/198472
More information about the llvm-commits
mailing list