Skip to content

Commit fe82465

Browse files
committed
[llvm][CodeGen] Resolve issues when updating live intervals in window scheduler
Corrupted live interval information can cause window scheduling to crash in some cases. By adding the missing MBB's live interval information in the ModuloScheduleExpander, the information can be correctly analyzed in the window scheduler.
1 parent b77cc53 commit fe82465

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

llvm/include/llvm/CodeGen/WindowScheduler.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ class WindowScheduler {
150150
/// Using the scheduling infrastructure to expand the results of window
151151
/// scheduling. It is usually necessary to add prologue and epilogue MBBs.
152152
virtual void expand();
153-
/// Reanalyze the live intervals in some scenarios.
154-
virtual void reanalyzeLiveIntervals();
155153
/// Update the live intervals for all registers used within MBB.
156154
virtual void updateLiveIntervals();
157155
/// Estimate a II value at which all MIs will be scheduled successfully.

llvm/lib/CodeGen/ModuloSchedule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ void ModuloScheduleExpander::generatePipelinedLoop() {
130130
// Generate the prolog instructions that set up the pipeline.
131131
generateProlog(MaxStageCount, KernelBB, VRMap, PrologBBs);
132132
MF.insert(BB->getIterator(), KernelBB);
133+
LIS.insertMBBInMaps(KernelBB);
133134

134135
// Rearrange the instructions to generate the new, pipelined loop,
135136
// and update register names as needed.
@@ -210,6 +211,7 @@ void ModuloScheduleExpander::generateProlog(unsigned LastStage,
210211
NewBB->transferSuccessors(PredBB);
211212
PredBB->addSuccessor(NewBB);
212213
PredBB = NewBB;
214+
LIS.insertMBBInMaps(NewBB);
213215

214216
// Generate instructions for each appropriate stage. Process instructions
215217
// in original program order.
@@ -283,6 +285,7 @@ void ModuloScheduleExpander::generateEpilog(
283285

284286
PredBB->replaceSuccessor(LoopExitBB, NewBB);
285287
NewBB->addSuccessor(LoopExitBB);
288+
LIS.insertMBBInMaps(NewBB);
286289

287290
if (EpilogStart == LoopExitBB)
288291
EpilogStart = NewBB;

llvm/lib/CodeGen/WindowScheduler.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ bool WindowScheduler::initialize() {
242242
LLVM_DEBUG(dbgs() << "There are too few MIs in the window region!\n");
243243
return false;
244244
}
245-
reanalyzeLiveIntervals();
246245
return true;
247246
}
248247

@@ -644,20 +643,6 @@ void WindowScheduler::expand() {
644643
MSE.cleanup();
645644
}
646645

647-
void WindowScheduler::reanalyzeLiveIntervals() {
648-
auto SlotIndex = Context->LIS->getSlotIndexes();
649-
// Check if the SlotIndex infomation is missing.
650-
for (auto &MBB : *MF)
651-
for (auto &MI : MBB)
652-
if (!SlotIndex->hasIndex(MI)) {
653-
// The slot index and live intervals of MF have been corrupted and need
654-
// to be reanalyzed.
655-
SlotIndex->reanalyze(*MF);
656-
Context->LIS->reanalyze(*MF);
657-
return;
658-
}
659-
}
660-
661646
void WindowScheduler::updateLiveIntervals() {
662647
SmallVector<Register, 128> UsedRegs;
663648
for (MachineInstr &MI : *MBB)

llvm/test/CodeGen/Hexagon/swp-ws-live-intervals.mir

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,21 @@
88
# The bug was reported at https://github.com/llvm/llvm-project/pull/99454.
99
# It is caused by the corruption of live intervals in certain scenarios.
1010
#
11+
# We check the newly generated MBBs after successful scheduling here.
1112
# CHECK: Best window offset is {{[0-9]+}} and Best II is {{[0-9]+}}.
13+
# CHECK: prolog:
14+
# CHECK: bb.5:
15+
# CHECK: New block
16+
# CHECK: bb.6:
17+
# CHECK: epilog:
18+
# CHECK: bb.7:
1219
# CHECK: Best window offset is {{[0-9]+}} and Best II is {{[0-9]+}}.
20+
# CHECK: prolog:
21+
# CHECK: bb.8:
22+
# CHECK: New block
23+
# CHECK: bb.9:
24+
# CHECK: epilog:
25+
# CHECK: bb.10:
1326

1427
--- |
1528
target triple = "hexagon"

0 commit comments

Comments
 (0)