[llvm] [llvm][CodeGen] Fix the issue caused by live interval checking in window scheduler (PR #123184)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 16 03:22:32 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-hexagon
Author: Hua Tian (huaatian)
<details>
<summary>Changes</summary>
At some corner cases, the cloned MI still retains a random slot index, which leads to the compiler crashing. Therefore, when we repair the slot index of the newly cloned MI, we first clear it.
https://github.com/llvm/llvm-project/issues/123165
---
Full diff: https://github.com/llvm/llvm-project/pull/123184.diff
2 Files Affected:
- (modified) llvm/lib/CodeGen/WindowScheduler.cpp (+4-1)
- (added) llvm/test/CodeGen/Hexagon/swp-ws-live-intervals-1.mir (+61)
``````````diff
diff --git a/llvm/lib/CodeGen/WindowScheduler.cpp b/llvm/lib/CodeGen/WindowScheduler.cpp
index f1658e36ae1e92..56e92ff9bde7f5 100644
--- a/llvm/lib/CodeGen/WindowScheduler.cpp
+++ b/llvm/lib/CodeGen/WindowScheduler.cpp
@@ -645,7 +645,7 @@ void WindowScheduler::expand() {
void WindowScheduler::updateLiveIntervals() {
SmallVector<Register, 128> UsedRegs;
- for (MachineInstr &MI : *MBB)
+ for (MachineInstr &MI : *MBB) {
for (const MachineOperand &MO : MI.operands()) {
if (!MO.isReg() || MO.getReg() == 0)
continue;
@@ -653,6 +653,9 @@ void WindowScheduler::updateLiveIntervals() {
if (!is_contained(UsedRegs, Reg))
UsedRegs.push_back(Reg);
}
+ // Remove the residual slot index of newly cloned MI.
+ Context->LIS->getSlotIndexes()->removeMachineInstrFromMaps(MI, true);
+ }
Context->LIS->repairIntervalsInRange(MBB, MBB->begin(), MBB->end(), UsedRegs);
}
diff --git a/llvm/test/CodeGen/Hexagon/swp-ws-live-intervals-1.mir b/llvm/test/CodeGen/Hexagon/swp-ws-live-intervals-1.mir
new file mode 100644
index 00000000000000..ae5e10b1eee1ff
--- /dev/null
+++ b/llvm/test/CodeGen/Hexagon/swp-ws-live-intervals-1.mir
@@ -0,0 +1,61 @@
+# REQUIRES: asserts
+#
+# RUN: llc --mtriple=hexagon %s -run-pass=pipeliner -debug-only=pipeliner \
+# RUN: -window-sched=force -filetype=null -verify-machineinstrs 2>&1\
+# RUN: | FileCheck %s
+
+# The bug was reported at https://github.com/llvm/llvm-project/issues/123165.
+# It is caused by the corruption of live intervals in certain scenarios.
+#
+# We check window scheduling logs to ensure that there is no crashing.
+# CHECK: Start analyzing II:
+# CHECK: MaxCycle is {{[0-9]+}}.
+# CHECK: MaxStallCycle is {{[0-9]+}}.
+# CHECK: Start scheduling Phis:
+# CHECK: Current window Offset is {{[0-9]+}} and II is {{[0-9]+}}.
+# CHECK: Window scheduling is not needed!
+
+...
+---
+name: _ZN10CInArchive17GetNextFolderItemEv
+tracksRegLiveness: true
+body: |
+ bb.0:
+ successors: %bb.1(0x80000000)
+ liveins: $r0
+
+ %0:intregs = COPY $r0
+ J2_loop0i %bb.1, 1, implicit-def $lc0, implicit-def $sa0, implicit-def $usr
+
+ bb.1:
+ successors: %bb.2(0x04000000), %bb.1(0x7c000000)
+
+ %1:intregs = L2_loadri_io %0, 0
+ %2:intregs = L2_loadrub_io killed %1, 0
+ %3:intregs = PS_loadriabs 0
+ S2_storerb_io killed %3, 0, killed %2
+ ENDLOOP0 %bb.1, implicit-def $pc, implicit-def $lc0, implicit $sa0, implicit $lc0
+
+ bb.2:
+ successors: %bb.4(0x80000000)
+
+ %4:intregs = A2_tfrsi 0
+ %5:intregs = A2_tfrsi -1
+ J2_loop0i %bb.4, 1, implicit-def $lc0, implicit-def $sa0, implicit-def $usr
+ J2_jump %bb.4, implicit-def $pc
+
+ bb.3:
+ S2_storeri_io %0, 0, %6
+ PS_jmpret $r31, implicit-def dead $pc
+
+ bb.4:
+ successors: %bb.3(0x04000000), %bb.4(0x7c000000)
+
+ %7:intregs = PHI %5, %bb.2, %8, %bb.4
+ %6:intregs = PHI %4, %bb.2, %9, %bb.4
+ %8:intregs = A2_addi %7, 1
+ %9:intregs = S2_setbit_i %8, 0
+ ENDLOOP0 %bb.4, implicit-def $pc, implicit-def $lc0, implicit $sa0, implicit $lc0
+ J2_jump %bb.3, implicit-def $pc
+
+...
``````````
</details>
https://github.com/llvm/llvm-project/pull/123184
More information about the llvm-commits
mailing list