Skip to content

Commit

Permalink
[llvm][CodeGen] Fix the issue caused by live interval checking in win…
Browse files Browse the repository at this point in the history
…dow scheduler (llvm#123184)

At some corner cases, the cloned MI still retains an old slot index,
which leads to the compiler crashing. This patch update the slot index
map before delete the recycled MI.

llvm#123165
  • Loading branch information
huaatian authored Jan 23, 2025
1 parent eaaac05 commit a9d2834
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 9 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/TargetInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ class TargetInstrInfo : public MCInstrInfo {
///
/// Once this function is called, no other functions on this object are
/// valid; the loop has been removed.
virtual void disposed() = 0;
virtual void disposed(LiveIntervals *LIS = nullptr) {}

/// Return true if the target can expand pipelined schedule with modulo
/// variable expansion.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/ModuloSchedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ void ModuloScheduleExpander::addBranches(MachineBasicBlock &PreheaderBB,
LastEpi->eraseFromParent();
}
if (LastPro == KernelBB) {
LoopInfo->disposed();
LoopInfo->disposed(&LIS);
NewKernel = nullptr;
}
LastPro->clear();
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10143,7 +10143,6 @@ class AArch64PipelinerLoopInfo : public TargetInstrInfo::PipelinerLoopInfo {

void adjustTripCount(int TripCountAdjust) override {}

void disposed() override {}
bool isMVEExpanderSupported() override { return true; }
};
} // namespace
Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6850,8 +6850,6 @@ class ARMPipelinerLoopInfo : public TargetInstrInfo::PipelinerLoopInfo {
void setPreheader(MachineBasicBlock *NewPreheader) override {}

void adjustTripCount(int TripCountAdjust) override {}

void disposed() override {}
};

void ARMPipelinerLoopInfo::bumpCrossIterationPressure(RegPressureTracker &RPT,
Expand Down
7 changes: 6 additions & 1 deletion llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/CodeGen/DFAPacketizer.h"
#include "llvm/CodeGen/LiveIntervals.h"
#include "llvm/CodeGen/LivePhysRegs.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
Expand Down Expand Up @@ -795,7 +796,11 @@ class HexagonPipelinerLoopInfo : public TargetInstrInfo::PipelinerLoopInfo {
Loop->getOperand(1).setReg(NewLoopCount);
}

void disposed() override { Loop->eraseFromParent(); }
void disposed(LiveIntervals *LIS) override {
if (LIS)
LIS->RemoveMachineInstrFromMaps(*Loop);
Loop->eraseFromParent();
}
};
} // namespace

Expand Down
6 changes: 5 additions & 1 deletion llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5693,7 +5693,11 @@ class PPCPipelinerLoopInfo : public TargetInstrInfo::PipelinerLoopInfo {
// so we don't need to generate any thing here.
}

void disposed() override {
void disposed(LiveIntervals *LIS) override {
if (LIS) {
LIS->RemoveMachineInstrFromMaps(*Loop);
LIS->RemoveMachineInstrFromMaps(*LoopCount);
}
Loop->eraseFromParent();
// Ensure the loop setup instruction is deleted too.
LoopCount->eraseFromParent();
Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4277,8 +4277,6 @@ class RISCVPipelinerLoopInfo : public TargetInstrInfo::PipelinerLoopInfo {
void setPreheader(MachineBasicBlock *NewPreheader) override {}

void adjustTripCount(int TripCountAdjust) override {}

void disposed() override {}
};
} // namespace

Expand Down
86 changes: 86 additions & 0 deletions llvm/test/CodeGen/Hexagon/swp-ws-live-intervals-issue123165.mir
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
# RUN: llc --mtriple=hexagon %s -run-pass=pipeliner -o -| FileCheck %s

...
---
name: test_swp_ws_live_intervals
tracksRegLiveness: true
body: |
; CHECK-LABEL: name: test_swp_ws_live_intervals
; CHECK: bb.0:
; CHECK-NEXT: successors: %bb.1(0x80000000)
; CHECK-NEXT: liveins: $r0
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:intregs = COPY $r0
; CHECK-NEXT: J2_loop0i %bb.1, 1, implicit-def $lc0, implicit-def $sa0, implicit-def $usr
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: bb.1:
; CHECK-NEXT: successors: %bb.2(0x04000000), %bb.1(0x7c000000)
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[L2_loadri_io:%[0-9]+]]:intregs = L2_loadri_io [[COPY]], 0
; CHECK-NEXT: [[L2_loadrub_io:%[0-9]+]]:intregs = L2_loadrub_io [[L2_loadri_io]], 0
; CHECK-NEXT: [[PS_loadriabs:%[0-9]+]]:intregs = PS_loadriabs 0
; CHECK-NEXT: S2_storerb_io [[PS_loadriabs]], 0, [[L2_loadrub_io]]
; CHECK-NEXT: ENDLOOP0 %bb.1, implicit-def $pc, implicit-def $lc0, implicit $sa0, implicit $lc0
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: bb.2:
; CHECK-NEXT: successors: %bb.5(0x80000000)
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[A2_tfrsi:%[0-9]+]]:intregs = A2_tfrsi 0
; CHECK-NEXT: [[A2_tfrsi1:%[0-9]+]]:intregs = A2_tfrsi -1
; CHECK-NEXT: J2_jump %bb.5, implicit-def $pc
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: bb.3:
; CHECK-NEXT: S2_storeri_io [[COPY]], 0, %18
; CHECK-NEXT: PS_jmpret $r31, implicit-def dead $pc
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: bb.5:
; CHECK-NEXT: successors: %bb.7(0x80000000)
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[A2_addi:%[0-9]+]]:intregs = A2_addi [[A2_tfrsi1]], 1
; CHECK-NEXT: J2_jump %bb.7, implicit-def $pc
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: bb.7:
; CHECK-NEXT: successors: %bb.3(0x80000000)
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[PHI:%[0-9]+]]:intregs = PHI [[A2_tfrsi]], %bb.5
; CHECK-NEXT: J2_jump %bb.3, implicit-def $pc
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

...

0 comments on commit a9d2834

Please sign in to comment.