[llvm] [CodeGen] Drop dead SlotIndexes before allocation (PR #224031)
Petar Jovanovic via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 9 02:18:33 PDT 2026
https://github.com/petar-jovanovic updated https://github.com/llvm/llvm-project/pull/224031
>From 3dbcc8f863767135979dec9d999747c48afb8259 Mon Sep 17 00:00:00 2001
From: Petar Jovanovic <petar.jovanovic at amd.com>
Date: Tue, 15 Sep 2026 17:27:48 +0200
Subject: [PATCH] [CodeGen] Drop dead SlotIndexes before allocation
SlotIndexes keeps the index list entry of an erased instruction and only
clears its instruction pointer. Live range sizes are measured in slot
indexes and greedy ranks ranges by size, so the leftovers inflate some
ranges more than others and reorder allocation, spilling heavily on
register-starved functions.
Add SlotIndexes::compactIndexes() to erase them. Erased entries are
unlinked, so LiveIntervals first reports the indexes it holds via
appendReferencedIndexes().
Off by default behind -greedy-compact-slot-indexes, since it changes
allocation across much of the test suite.
---
llvm/include/llvm/CodeGen/LiveIntervals.h | 4 +
llvm/include/llvm/CodeGen/SlotIndexes.h | 29 ++-
llvm/lib/CodeGen/LiveIntervals.cpp | 29 +++
llvm/lib/CodeGen/RegAllocGreedy.cpp | 13 +-
llvm/lib/CodeGen/SlotIndexes.cpp | 46 ++++
.../AMDGPU/greedy-compact-slot-indexes.ll | 32 +++
llvm/unittests/CodeGen/SlotIndexesTest.cpp | 221 ++++++++++++++++++
7 files changed, 367 insertions(+), 7 deletions(-)
create mode 100644 llvm/test/CodeGen/AMDGPU/greedy-compact-slot-indexes.ll
diff --git a/llvm/include/llvm/CodeGen/LiveIntervals.h b/llvm/include/llvm/CodeGen/LiveIntervals.h
index 966c38692d0048..98462a7d468768 100644
--- a/llvm/include/llvm/CodeGen/LiveIntervals.h
+++ b/llvm/include/llvm/CodeGen/LiveIntervals.h
@@ -252,6 +252,10 @@ class LiveIntervals {
SlotIndexes *getSlotIndexes() const { return Indexes; }
+ /// Append every SlotIndex held here. See SlotIndexes::compactIndexes.
+ LLVM_ABI void
+ appendReferencedIndexes(SmallVectorImpl<SlotIndex> &Indexes) const;
+
/// Returns true if the specified machine instr has been removed or was
/// never entered in the map.
bool isNotInMIMap(const MachineInstr &Instr) const {
diff --git a/llvm/include/llvm/CodeGen/SlotIndexes.h b/llvm/include/llvm/CodeGen/SlotIndexes.h
index 542a6beb0ed016..65079c7e01b413 100644
--- a/llvm/include/llvm/CodeGen/SlotIndexes.h
+++ b/llvm/include/llvm/CodeGen/SlotIndexes.h
@@ -47,10 +47,14 @@ class raw_ostream;
class IndexListEntry : public ilist_node<IndexListEntry> {
MachineInstr *mi;
unsigned index;
+ bool erased = false;
public:
IndexListEntry(MachineInstr *mi, unsigned index) : mi(mi), index(index) {}
+ bool isErased() const { return erased; }
+ void setErased() { erased = true; }
+
MachineInstr* getInstr() const { return mi; }
void setInstr(MachineInstr *mi) {
this->mi = mi;
@@ -99,6 +103,14 @@ class raw_ostream;
return lie.getPointer();
}
+ /// For operations that cannot use an erased entry. Comparison still can.
+ IndexListEntry *linkedEntry() const {
+ assert(!listEntry()->isErased() &&
+ "SlotIndex outlived the instruction it pointed at; the analysis "
+ "holding it must report it to SlotIndexes::compactIndexes");
+ return listEntry();
+ }
+
unsigned getIndex() const {
return listEntry()->getIndex() | getSlot();
}
@@ -250,7 +262,7 @@ class raw_ostream;
SlotIndex getNextSlot() const {
Slot s = getSlot();
if (s == Slot_Dead) {
- return SlotIndex(&*++listEntry()->getIterator(), Slot_Block);
+ return SlotIndex(&*++linkedEntry()->getIterator(), Slot_Block);
}
return SlotIndex(listEntry(), s + 1);
}
@@ -258,7 +270,7 @@ class raw_ostream;
/// Returns the next index. This is the index corresponding to the this
/// index's slot, but for the next instruction.
SlotIndex getNextIndex() const {
- return SlotIndex(&*++listEntry()->getIterator(), getSlot());
+ return SlotIndex(&*++linkedEntry()->getIterator(), getSlot());
}
/// Returns the previous slot in the index list. This could be either the
@@ -270,7 +282,7 @@ class raw_ostream;
SlotIndex getPrevSlot() const {
Slot s = getSlot();
if (s == Slot_Block) {
- return SlotIndex(&*--listEntry()->getIterator(), Slot_Dead);
+ return SlotIndex(&*--linkedEntry()->getIterator(), Slot_Dead);
}
return SlotIndex(listEntry(), s - 1);
}
@@ -278,7 +290,7 @@ class raw_ostream;
/// Returns the previous index. This is the index corresponding to this
/// index's slot, but for the previous instruction.
SlotIndex getPrevIndex() const {
- return SlotIndex(&*--listEntry()->getIterator(), getSlot());
+ return SlotIndex(&*--linkedEntry()->getIterator(), getSlot());
}
};
@@ -393,7 +405,7 @@ class raw_ostream;
/// Returns the instruction for the given index, or null if the given
/// index has no instruction associated with it.
MachineInstr* getInstructionFromIndex(SlotIndex index) const {
- return index.listEntry()->getInstr();
+ return index.linkedEntry()->getInstr();
}
/// Returns true if \p Idx refers to an entry created to mark a basic block
@@ -413,7 +425,7 @@ class raw_ostream;
/// Returns the next non-null index, if one exists.
/// Otherwise returns getLastIndex().
SlotIndex getNextNonNullIndex(SlotIndex Index) {
- IndexList::iterator I = Index.listEntry()->getIterator();
+ IndexList::iterator I = Index.linkedEntry()->getIterator();
IndexList::iterator E = indexList.end();
while (++I != E)
if (I->getInstr())
@@ -653,6 +665,11 @@ class raw_ostream;
/// Renumber all indexes using the default instruction distance.
LLVM_ABI void packIndexes();
+
+ /// Erase index list entries left behind by deleted instructions, then
+ /// renumber. Erased entries are unlinked, so \p Referenced must name every
+ /// index held anywhere, not just the caller's. Returns the number erased.
+ LLVM_ABI unsigned compactIndexes(ArrayRef<SlotIndex> Referenced);
};
// Specialize IntervalMapInfo for half-open slot index intervals.
diff --git a/llvm/lib/CodeGen/LiveIntervals.cpp b/llvm/lib/CodeGen/LiveIntervals.cpp
index b0c18d5d5fe5da..5f76c5292aae54 100644
--- a/llvm/lib/CodeGen/LiveIntervals.cpp
+++ b/llvm/lib/CodeGen/LiveIntervals.cpp
@@ -180,6 +180,35 @@ void LiveIntervals::analyze(MachineFunction &fn) {
}
}
+void LiveIntervals::appendReferencedIndexes(
+ SmallVectorImpl<SlotIndex> &Indexes) const {
+ llvm::append_range(Indexes, RegMaskSlots);
+
+ auto CollectRange = [&Indexes](const LiveRange &LR) {
+ for (const LiveRange::Segment &S : LR) {
+ Indexes.push_back(S.start);
+ Indexes.push_back(S.end);
+ }
+ for (const VNInfo *VNI : LR.valnos)
+ if (VNI && !VNI->isUnused())
+ Indexes.push_back(VNI->def);
+ };
+
+ for (unsigned I = 0, E = MRI->getNumVirtRegs(); I != E; ++I) {
+ Register Reg = Register::index2VirtReg(I);
+ if (!hasInterval(Reg))
+ continue;
+ const LiveInterval &LI = getInterval(Reg);
+ CollectRange(LI);
+ for (const LiveInterval::SubRange &SR : LI.subranges())
+ CollectRange(SR);
+ }
+
+ for (const LiveRange *LR : RegUnitRanges)
+ if (LR)
+ CollectRange(*LR);
+}
+
void LiveIntervals::print(raw_ostream &OS) const {
OS << "********** INTERVALS **********\n";
diff --git a/llvm/lib/CodeGen/RegAllocGreedy.cpp b/llvm/lib/CodeGen/RegAllocGreedy.cpp
index 51faa9dd91039e..44a1bff232dc07 100644
--- a/llvm/lib/CodeGen/RegAllocGreedy.cpp
+++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp
@@ -108,6 +108,11 @@ static cl::opt<bool> ExhaustiveSearch(
"and interference cutoffs of last chance recoloring"),
cl::Hidden);
+static cl::opt<bool> CompactSlotIndexes(
+ "greedy-compact-slot-indexes", cl::Hidden, cl::init(false),
+ cl::desc("Drop SlotIndexes entries for erased instructions before "
+ "allocating, so live range sizes reflect real code distance"));
+
// This option should be deprecated!
// FIXME: Find a good default for this flag and remove the flag.
static cl::opt<unsigned>
@@ -2968,7 +2973,13 @@ bool RAGreedy::run(MachineFunction &mf) {
// Renumber to get accurate and consistent results from
// SlotIndexes::getApproxInstrDistance.
- Indexes->packIndexes();
+ if (CompactSlotIndexes) {
+ SmallVector<SlotIndex, 0> Referenced;
+ LIS->appendReferencedIndexes(Referenced);
+ Indexes->compactIndexes(Referenced);
+ } else {
+ Indexes->packIndexes();
+ }
initializeCSRCost();
diff --git a/llvm/lib/CodeGen/SlotIndexes.cpp b/llvm/lib/CodeGen/SlotIndexes.cpp
index b141cd1c8aa271..6ebc0439a0cc00 100644
--- a/llvm/lib/CodeGen/SlotIndexes.cpp
+++ b/llvm/lib/CodeGen/SlotIndexes.cpp
@@ -46,6 +46,8 @@ INITIALIZE_PASS(SlotIndexesWrapperPass, DEBUG_TYPE, "Slot index numbering",
false, false)
STATISTIC(NumLocalRenum, "Number of local renumberings");
+STATISTIC(NumDeadEntriesErased,
+ "Number of index list entries erased for deleted instructions");
void SlotIndexesWrapperPass::getAnalysisUsage(AnalysisUsage &au) const {
au.setPreservesAll();
@@ -322,6 +324,50 @@ void SlotIndexes::packIndexes() {
Entry.setIndex(Index * SlotIndex::InstrDist);
}
+unsigned SlotIndexes::compactIndexes(ArrayRef<SlotIndex> Referenced) {
+ if (indexList.empty())
+ return 0;
+
+ SmallPtrSet<const IndexListEntry *, 32> Keep;
+
+ // The first and last entries anchor getZeroIndex() and getLastIndex().
+ Keep.insert(&indexList.front());
+ Keep.insert(&indexList.back());
+
+ for (const auto &Range : MBBRanges) {
+ if (Range.first.isValid())
+ Keep.insert(Range.first.listEntry());
+ if (Range.second.isValid())
+ Keep.insert(Range.second.listEntry());
+ }
+ for (SlotIndex Idx : Referenced)
+ if (Idx.isValid())
+ Keep.insert(Idx.linkedEntry());
+
+ // Entries must be unlinked, not zero-width: that would break getNextSlot().
+ SmallVector<IndexListEntry *, 16> Erased;
+ unsigned Index = 0;
+ for (auto It = indexList.begin(), E = indexList.end(); It != E;) {
+ IndexListEntry &Entry = *It++;
+ if (Entry.getInstr() || Keep.contains(&Entry)) {
+ Entry.setIndex(Index);
+ Index += SlotIndex::InstrDist;
+ continue;
+ }
+ // Take the surviving entry behind, so a stale index stays in program order.
+ assert(Index != 0 && "First entry is always kept");
+ Entry.setIndex(Index - SlotIndex::InstrDist);
+ Erased.push_back(&Entry);
+ indexList.remove(Entry);
+ }
+
+ for (IndexListEntry *Entry : Erased)
+ Entry->setErased();
+
+ NumDeadEntriesErased += Erased.size();
+ return Erased.size();
+}
+
void SlotIndexes::print(raw_ostream &OS) const {
for (const IndexListEntry &ILE : indexList) {
OS << ILE.getIndex() << ' ';
diff --git a/llvm/test/CodeGen/AMDGPU/greedy-compact-slot-indexes.ll b/llvm/test/CodeGen/AMDGPU/greedy-compact-slot-indexes.ll
new file mode 100644
index 00000000000000..ec79a283f3c266
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/greedy-compact-slot-indexes.ll
@@ -0,0 +1,32 @@
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -O3 -stress-regalloc=8 \
+; RUN: -greedy-compact-slot-indexes -verify-machineinstrs -filetype=null < %s
+
+; AMDGPU runs greedy three times against one LiveDebugVariables, whose indexes
+; must survive compaction for the DBG_VALUEs to still be emittable.
+
+define amdgpu_kernel void @sdiv_i32_pow2_shl_denom(ptr addrspace(1) %out, i32 %x, i32 %y) !dbg !5 {
+ %shl.y = shl i32 4096, %y, !dbg !12
+ #dbg_value(i32 %shl.y, !9, !DIExpression(), !12)
+ %r = sdiv i32 %x, %shl.y, !dbg !13
+ #dbg_value(i32 %r, !11, !DIExpression(), !13)
+ store i32 %r, ptr addrspace(1) %out, align 4, !dbg !14
+ ret void, !dbg !15
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!4}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
+!1 = !DIFile(filename: "t.ll", directory: "/")
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = distinct !DISubprogram(name: "sdiv_i32_pow2_shl_denom", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
+!6 = !DISubroutineType(types: !7)
+!7 = !{}
+!8 = !{!9, !11}
+!9 = !DILocalVariable(name: "1", scope: !5, file: !1, line: 1, type: !10)
+!10 = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned)
+!11 = !DILocalVariable(name: "2", scope: !5, file: !1, line: 2, type: !10)
+!12 = !DILocation(line: 1, column: 1, scope: !5)
+!13 = !DILocation(line: 2, column: 1, scope: !5)
+!14 = !DILocation(line: 3, column: 1, scope: !5)
+!15 = !DILocation(line: 4, column: 1, scope: !5)
diff --git a/llvm/unittests/CodeGen/SlotIndexesTest.cpp b/llvm/unittests/CodeGen/SlotIndexesTest.cpp
index 1725fbe2190fe5..3682ec795c8cff 100644
--- a/llvm/unittests/CodeGen/SlotIndexesTest.cpp
+++ b/llvm/unittests/CodeGen/SlotIndexesTest.cpp
@@ -8,7 +8,9 @@
#include "llvm/CodeGen/SlotIndexes.h"
#include "CodeGenTestBase.h"
+#include "llvm/CodeGen/LiveIntervals.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
+#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/Config/Targets.h"
#include "llvm/Support/TargetSelect.h"
#include "gtest/gtest.h"
@@ -204,4 +206,223 @@ body: |
EXPECT_TRUE(SI.isBlockBoundaryIndex(SI.getMBBEndIdx(&MBB)));
}
+/// Deletes \p MI the way a real pass does: its index list entry survives.
+static void deleteInstr(MachineInstr &MI, LiveIntervals &LIS) {
+ for (const MachineOperand &MO : MI.all_defs())
+ if (MO.getReg().isVirtual() && LIS.hasInterval(MO.getReg()))
+ LIS.removeInterval(MO.getReg());
+ LIS.RemoveMachineInstrFromMaps(MI);
+ MI.eraseFromParent();
+}
+
+/// Compacts on behalf of a caller whose only index holder is \p LIS.
+static unsigned compact(LiveIntervals &LIS) {
+ SmallVector<SlotIndex, 0> Referenced;
+ LIS.appendReferencedIndexes(Referenced);
+ return LIS.getSlotIndexes()->compactIndexes(Referenced);
+}
+
+/// Leftover entries inflate live range sizes, which is what misled the
+/// allocator. Compaction must restore the real def-to-use size.
+TEST_F(SlotIndexesTest, CompactIndexesShrinksSizeToRealDistance) {
+ StringRef MIRString = R"(
+---
+name: func
+tracksRegLiveness: true
+machineFunctionInfo:
+ isEntryFunction: true
+body: |
+ bb.0:
+ %0:vgpr_32 = IMPLICIT_DEF
+ %1:vgpr_32 = IMPLICIT_DEF
+ %2:vgpr_32 = IMPLICIT_DEF
+ %3:vgpr_32 = IMPLICIT_DEF
+ S_NOP 0, implicit %0
+ S_ENDPGM 0
+...
+ )";
+ ASSERT_TRUE(parseMIR(MIRString));
+
+ MachineFunction &MF = getMF("func");
+ LiveIntervals &LIS = MFAM.getResult<LiveIntervalsAnalysis>(MF);
+ MachineBasicBlock &MBB = *MF.getBlockNumbered(0);
+
+ const Register Tracked = Register::index2VirtReg(0);
+ EXPECT_EQ(LIS.getInterval(Tracked).getSize(), 4u * SlotIndex::InstrDist);
+
+ for (Register Reg : {Register::index2VirtReg(1), Register::index2VirtReg(2),
+ Register::index2VirtReg(3)})
+ deleteInstr(*MF.getRegInfo().getVRegDef(Reg), LIS);
+ ASSERT_EQ(std::distance(MBB.begin(), MBB.end()), 3L);
+
+ // Deleting does not renumber, so the size is unchanged.
+ EXPECT_EQ(LIS.getInterval(Tracked).getSize(), 4u * SlotIndex::InstrDist);
+
+ EXPECT_EQ(compact(LIS), 3u);
+
+ EXPECT_EQ(LIS.getInterval(Tracked).getSize(), 1u * SlotIndex::InstrDist);
+ EXPECT_TRUE(MF.verify(&LIS, LIS.getSlotIndexes(), /*Banner=*/nullptr,
+ /*OS=*/&errs(), /*AbortOnError=*/false));
+}
+
+/// A referenced entry must survive: here the use of %0 is taken out of the
+/// index maps while %0's live range still ends on it.
+TEST_F(SlotIndexesTest, CompactIndexesKeepsReferencedEntries) {
+ StringRef MIRString = R"(
+---
+name: func
+tracksRegLiveness: true
+machineFunctionInfo:
+ isEntryFunction: true
+body: |
+ bb.0:
+ %0:vgpr_32 = IMPLICIT_DEF
+ S_NOP 0, implicit %0
+ S_ENDPGM 0
+...
+ )";
+ ASSERT_TRUE(parseMIR(MIRString));
+
+ MachineFunction &MF = getMF("func");
+ LiveIntervals &LIS = MFAM.getResult<LiveIntervalsAnalysis>(MF);
+ MachineBasicBlock &MBB = *MF.getBlockNumbered(0);
+
+ const Register Tracked = Register::index2VirtReg(0);
+ const SlotIndex End = LIS.getInterval(Tracked).endIndex();
+
+ MachineInstr &Use = *std::next(MBB.begin());
+ LIS.RemoveMachineInstrFromMaps(Use);
+
+ EXPECT_EQ(compact(LIS), 0u);
+ EXPECT_EQ(LIS.getInterval(Tracked).endIndex(), End);
+}
+
+/// Block boundary entries carry no instruction by design, so compaction must
+/// not mistake them for leftovers.
+TEST_F(SlotIndexesTest, CompactIndexesKeepsBlockBoundaries) {
+ StringRef MIRString = R"(
+---
+name: func
+tracksRegLiveness: true
+machineFunctionInfo:
+ isEntryFunction: true
+body: |
+ bb.0:
+ %0:vgpr_32 = IMPLICIT_DEF
+ %1:vgpr_32 = IMPLICIT_DEF
+ S_CMP_EQ_U32 0, 0, implicit-def $scc
+ S_CBRANCH_SCC1 %bb.2, implicit $scc
+
+ bb.1:
+ %2:vgpr_32 = IMPLICIT_DEF
+ S_NOP 0, implicit %0
+
+ bb.2:
+ S_ENDPGM 0
+...
+ )";
+ ASSERT_TRUE(parseMIR(MIRString));
+
+ MachineFunction &MF = getMF("func");
+ LiveIntervals &LIS = MFAM.getResult<LiveIntervalsAnalysis>(MF);
+ SlotIndexes &SI = *LIS.getSlotIndexes();
+
+ deleteInstr(*MF.getRegInfo().getVRegDef(Register::index2VirtReg(1)), LIS);
+ deleteInstr(*MF.getRegInfo().getVRegDef(Register::index2VirtReg(2)), LIS);
+
+ EXPECT_EQ(compact(LIS), 2u);
+
+ for (MachineBasicBlock &MBB : MF) {
+ SlotIndex Start = LIS.getMBBStartIdx(&MBB);
+ EXPECT_TRUE(Start.isValid());
+ EXPECT_EQ(SI.getMBBFromIndex(Start), &MBB);
+ EXPECT_LT(Start, LIS.getMBBEndIdx(&MBB));
+ }
+
+ EXPECT_TRUE(MF.verify(&LIS, &SI, /*Banner=*/nullptr, /*OS=*/&errs(),
+ /*AbortOnError=*/false));
+}
+
+/// An unreported index still has to compare sanely, since only an asserts
+/// build diagnoses it. It takes the index of the surviving entry behind it.
+TEST_F(SlotIndexesTest, CompactIndexesKeepsStaleIndexesInProgramOrder) {
+ StringRef MIRString = R"(
+---
+name: func
+tracksRegLiveness: true
+machineFunctionInfo:
+ isEntryFunction: true
+body: |
+ bb.0:
+ %0:vgpr_32 = IMPLICIT_DEF
+ %1:vgpr_32 = IMPLICIT_DEF
+ %2:vgpr_32 = IMPLICIT_DEF
+ %3:vgpr_32 = IMPLICIT_DEF
+ S_NOP 0, implicit %0
+ S_ENDPGM 0
+...
+ )";
+ ASSERT_TRUE(parseMIR(MIRString));
+
+ MachineFunction &MF = getMF("func");
+ LiveIntervals &LIS = MFAM.getResult<LiveIntervalsAnalysis>(MF);
+ SlotIndexes &SI = *LIS.getSlotIndexes();
+ MachineBasicBlock &MBB = *MF.getBlockNumbered(0);
+
+ const SlotIndex Behind = LIS.getInstructionIndex(*MBB.begin()).getBaseIndex();
+ SmallVector<SlotIndex, 3> Stale;
+ for (unsigned I : {1u, 2u, 3u}) {
+ MachineInstr &MI = *MF.getRegInfo().getVRegDef(Register::index2VirtReg(I));
+ Stale.push_back(LIS.getInstructionIndex(MI).getBaseIndex());
+ }
+ for (unsigned I : {1u, 2u, 3u})
+ deleteInstr(*MF.getRegInfo().getVRegDef(Register::index2VirtReg(I)), LIS);
+
+ ASSERT_EQ(compact(LIS), 3u);
+
+ for (SlotIndex S : Stale) {
+ EXPECT_LT(S, SI.getLastIndex());
+ // Ordered with the entry behind, but no longer distinct from it.
+ EXPECT_FALSE(S < Behind);
+ EXPECT_FALSE(Behind < S);
+ EXPECT_FALSE(S == Behind);
+ }
+}
+
+/// No caller can check that every holder reported, so an unreported index is
+/// diagnosed at the point of use rather than followed.
+#if !defined(NDEBUG) && defined(GTEST_HAS_DEATH_TEST)
+TEST_F(SlotIndexesTest, CompactIndexesFlagsUnreportedStaleIndex) {
+ StringRef MIRString = R"(
+---
+name: func
+tracksRegLiveness: true
+machineFunctionInfo:
+ isEntryFunction: true
+body: |
+ bb.0:
+ %0:vgpr_32 = IMPLICIT_DEF
+ %1:vgpr_32 = IMPLICIT_DEF
+ S_NOP 0, implicit %0
+ S_ENDPGM 0
+...
+ )";
+ ASSERT_TRUE(parseMIR(MIRString));
+
+ MachineFunction &MF = getMF("func");
+ LiveIntervals &LIS = MFAM.getResult<LiveIntervalsAnalysis>(MF);
+ SlotIndexes &SI = *LIS.getSlotIndexes();
+
+ MachineInstr &Dead = *MF.getRegInfo().getVRegDef(Register::index2VirtReg(1));
+ // An outside holder that never reports this index.
+ const SlotIndex Stale = LIS.getInstructionIndex(Dead).getBaseIndex();
+ deleteInstr(Dead, LIS);
+
+ ASSERT_EQ(compact(LIS), 1u);
+
+ EXPECT_DEATH((void)SI.getInstructionFromIndex(Stale),
+ "SlotIndex outlived the instruction it pointed at");
+}
+#endif
+
} // namespace
More information about the llvm-commits
mailing list