Skip to content

Commit 355e4a9

Browse files
authored
[llvm][CodeGen] Fix failure in window scheduler caused by weak dependencies (#95636)
This commit addresses an issue where weak dependencies trigger an assertion in the window scheduler under certain conditions.
1 parent ef01c75 commit 355e4a9

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

llvm/lib/CodeGen/WindowScheduler.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ int WindowScheduler::calculateMaxCycle(ScheduleDAGInstrs &DAG,
422422
int ExpectCycle = CurCycle;
423423
// The predecessors of current MI determine its earliest issue cycle.
424424
for (auto &Pred : SU->Preds) {
425+
if (Pred.isWeak())
426+
continue;
425427
auto *PredMI = Pred.getSUnit()->getInstr();
426428
int PredCycle = getOriCycle(PredMI);
427429
ExpectCycle = std::max(ExpectCycle, PredCycle + (int)Pred.getLatency());
@@ -479,7 +481,7 @@ int WindowScheduler::calculateStallCycle(unsigned Offset, int MaxCycle) {
479481
auto *SU = TripleDAG->getSUnit(&MI);
480482
int DefCycle = getOriCycle(&MI);
481483
for (auto &Succ : SU->Succs) {
482-
if (Succ.getSUnit() == &TripleDAG->ExitSU)
484+
if (Succ.isWeak() || Succ.getSUnit() == &TripleDAG->ExitSU)
483485
continue;
484486
// If the expected cycle does not exceed MaxCycle, no check is needed.
485487
if (DefCycle + (int)Succ.getLatency() <= MaxCycle)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# REQUIRES: asserts
2+
# RUN: llc --march=hexagon %s -run-pass=pipeliner -debug-only=pipeliner \
3+
# RUN: -window-sched=force -filetype=null 2>&1 | FileCheck %s
4+
5+
# CHECK: SU(3): Ord Latency=0 Weak
6+
# CHECK: SU(1): Ord Latency=0 Weak
7+
# CHECK: Window scheduling is not needed!
8+
9+
---
10+
name: khazad_setkey_in_key
11+
tracksRegLiveness: true
12+
body: |
13+
bb.0:
14+
successors: %bb.1(0x80000000)
15+
liveins: $r0, $r1
16+
17+
%0:intregs = COPY $r1
18+
%1:intregs = COPY $r0
19+
J2_loop0i %bb.1, 1, implicit-def $lc0, implicit-def $sa0, implicit-def $usr
20+
21+
bb.1:
22+
successors: %bb.2(0x04000000), %bb.1(0x7c000000)
23+
24+
%2:doubleregs = L2_loadrd_io %1, 0
25+
%3:intregs = COPY %2.isub_lo
26+
S2_storeri_io %0, 0, %3
27+
%4:intregs = S2_asl_i_r %2.isub_hi, 2
28+
%5:intregs = L2_loadri_io %4, 0
29+
%6:intregs = S4_andi_asl_ri 4, %3, 1
30+
%7:intregs = L2_loadri_io %6, 0
31+
%8:intregs = A2_xor %7, %5
32+
S2_storeri_io %1, 0, %8
33+
ENDLOOP0 %bb.1, implicit-def $pc, implicit-def $lc0, implicit $sa0, implicit $lc0
34+
J2_jump %bb.2, implicit-def dead $pc
35+
36+
bb.2:
37+
PS_jmpret $r31, implicit-def dead $pc
38+
39+
...

0 commit comments

Comments
 (0)