Skip to content

Commit 5a164a2

Browse files
kaiyan96tru
authored andcommittedSep 1, 2024
[llvm][CodeGen] Fixed max cycle calculation with zero-cost instructions for window scheduler (#99454)
We discovered some scheduling failures occurring when zero-cost instructions were involved. This issue will be addressed by this patch.
1 parent 06d0097 commit 5a164a2

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed
 

Diff for: ‎llvm/lib/CodeGen/WindowScheduler.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,16 @@ int WindowScheduler::calculateMaxCycle(ScheduleDAGInstrs &DAG,
440440
int PredCycle = getOriCycle(PredMI);
441441
ExpectCycle = std::max(ExpectCycle, PredCycle + (int)Pred.getLatency());
442442
}
443-
// ResourceManager can be used to detect resource conflicts between the
444-
// current MI and the previously inserted MIs.
445-
while (!RM.canReserveResources(*SU, CurCycle) || CurCycle < ExpectCycle) {
446-
++CurCycle;
447-
if (CurCycle == (int)WindowIILimit)
448-
return CurCycle;
443+
// Zero cost instructions do not need to check resource.
444+
if (!TII->isZeroCost(MI.getOpcode())) {
445+
// ResourceManager can be used to detect resource conflicts between the
446+
// current MI and the previously inserted MIs.
447+
while (!RM.canReserveResources(*SU, CurCycle) || CurCycle < ExpectCycle) {
448+
++CurCycle;
449+
if (CurCycle == (int)WindowIILimit)
450+
return CurCycle;
451+
}
452+
RM.reserveResources(*SU, CurCycle);
449453
}
450454
RM.reserveResources(*SU, CurCycle);
451455
OriToCycle[getOriMI(&MI)] = CurCycle;

Diff for: ‎llvm/test/CodeGen/Hexagon/swp-ws-zero-cost.mir

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# REQUIRES: asserts
2+
# RUN: llc --march=hexagon %s -run-pass=pipeliner -debug-only=pipeliner \
3+
# RUN: -window-sched=force -filetype=null -verify-machineinstrs 2>&1 \
4+
# RUN: | FileCheck %s
5+
6+
# CHECK-NOT: Can't find a valid II. Keep searching...
7+
# CHECK: Start analyzing II
8+
# CHECK: Start scheduling Phis
9+
# CHECK: Current window Offset is {{[0-9]+}} and II is {{[0-9]+}}
10+
11+
---
12+
name: relu
13+
tracksRegLiveness: true
14+
body: |
15+
bb.0:
16+
successors: %bb.2(0x30000000), %bb.1(0x50000000)
17+
liveins: $r0, $r1, $r2
18+
%0:intregs = COPY $r2
19+
%1:intregs = COPY $r1
20+
%2:intregs = COPY $r0
21+
%3:predregs = C2_cmpeqi %2, 0
22+
J2_jumpt killed %3, %bb.2, implicit-def dead $pc
23+
J2_jump %bb.1, implicit-def dead $pc
24+
bb.1:
25+
successors: %bb.3(0x80000000)
26+
%4:hvxvr = V6_vd0
27+
%5:intregs = A2_addi %2, 31
28+
%6:intregs = S2_lsr_i_r %5, 5
29+
%7:intregs = COPY %6
30+
J2_loop0r %bb.3, %7, implicit-def $lc0, implicit-def $sa0, implicit-def $usr
31+
J2_jump %bb.3, implicit-def dead $pc
32+
bb.2:
33+
PS_jmpret $r31, implicit-def dead $pc
34+
bb.3 (machine-block-address-taken):
35+
successors: %bb.3(0x7c000000), %bb.2(0x04000000)
36+
%8:intregs = PHI %1, %bb.1, %9, %bb.3
37+
%10:intregs = PHI %0, %bb.1, %14, %bb.3
38+
%11:hvxvr, %9:intregs = V6_vL32b_pi %8, 128
39+
%12:intregs = COPY %10
40+
%13:hvxvr = V6_vmaxw killed %11, %4
41+
%14:intregs = V6_vS32b_pi %12, 128, killed %13
42+
ENDLOOP0 %bb.3, implicit-def $pc, implicit-def $lc0, implicit $sa0, implicit $lc0
43+
J2_jump %bb.2, implicit-def dead $pc
44+
...
45+

0 commit comments

Comments
 (0)