Skip to content

Commit 4700d4e

Browse files
huaatianAlexisPerry
authored andcommitted
[llvm][CodeGen] Fix failure in window scheduler caused by phi (llvm#95900)
In certain cases, the register passed with the kernel MBB in phi are not defined within the kernel MBB. This patch adds the corresponding handling.
1 parent 879e506 commit 4700d4e

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

llvm/lib/CodeGen/WindowScheduler.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,12 @@ void WindowScheduler::schedulePhi(int Offset, unsigned &II) {
533533
// The anti-dependency of phi need to be handled separately in the same way.
534534
if (Register AntiReg = getAntiRegister(&Phi)) {
535535
auto *AntiMI = MRI->getVRegDef(AntiReg);
536-
auto AntiCycle = getOriCycle(AntiMI);
537-
if (getOriStage(getOriMI(AntiMI), Offset) == 0)
538-
LateCycle = std::min(LateCycle, AntiCycle);
536+
// AntiReg may be defined outside the kernel MBB.
537+
if (AntiMI->getParent() == MBB) {
538+
auto AntiCycle = getOriCycle(AntiMI);
539+
if (getOriStage(getOriMI(AntiMI), Offset) == 0)
540+
LateCycle = std::min(LateCycle, AntiCycle);
541+
}
539542
}
540543
// If there is no limit to the late cycle, a default value is given.
541544
if (LateCycle == INT_MAX)
@@ -683,7 +686,7 @@ Register WindowScheduler::getAntiRegister(MachineInstr *Phi) {
683686
for (auto MO : Phi->uses()) {
684687
if (MO.isReg())
685688
AntiReg = MO.getReg();
686-
else if (MO.isMBB() && MO.getMBB()->getNumber() == MBB->getNumber())
689+
else if (MO.isMBB() && MO.getMBB() == MBB)
687690
return AntiReg;
688691
}
689692
return 0;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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: Window scheduling is not needed!
6+
# CHECK-LABEL: body: |
7+
# CHECK: bb.0:
8+
# CHECK: [[REG:%[0-9]+]]:intregs = A2_tfrsi 0
9+
# CHECK: bb.2:
10+
# CHECK: {{%[0-9]+}}:intregs = PHI {{%[0-9]+}}, %bb.0, [[REG]], %bb.2
11+
12+
---
13+
name: poll_for_response
14+
tracksRegLiveness: true
15+
body: |
16+
bb.0:
17+
successors: %bb.2(0x80000000)
18+
liveins: $r0, $r1
19+
20+
%0:intregs = COPY $r1
21+
%1:intregs = COPY $r0
22+
%2:intregs = A2_tfrsi 0
23+
J2_loop0i %bb.2, 2, implicit-def $lc0, implicit-def $sa0, implicit-def $usr
24+
J2_jump %bb.2, implicit-def dead $pc
25+
26+
bb.1:
27+
PS_jmpret $r31, implicit-def dead $pc
28+
29+
bb.2:
30+
successors: %bb.1(0x04000000), %bb.2(0x7c000000)
31+
32+
%3:intregs = PHI %1, %bb.0, %2, %bb.2
33+
%4:intregs = PHI %2, %bb.0, %5, %bb.2
34+
%6:intregs = S2_lsr_i_r %3, 1
35+
S2_storerb_io %0, 0, killed %6
36+
S4_storerb_rr %0, %4, 0, %2
37+
%5:intregs = A2_tfrsi 1
38+
ENDLOOP0 %bb.2, implicit-def $pc, implicit-def $lc0, implicit $sa0, implicit $lc0
39+
J2_jump %bb.1, implicit-def $pc
40+
41+
...

0 commit comments

Comments
 (0)