Skip to content

Commit 66b1675

Browse files
committed
[AMDGPU] Skip non-first termintors when forcing emit zero flag
1 parent ed77df5 commit 66b1675

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1824,7 +1824,14 @@ bool SIInsertWaitcnts::generateWaitcntInstBefore(MachineInstr &MI,
18241824
// Verify that the wait is actually needed.
18251825
ScoreBrackets.simplifyWaitcnt(Wait);
18261826

1827-
if (ForceEmitZeroFlag)
1827+
// When forcing emit, we need to skip non-first terminators of a MBB because
1828+
// that would break the terminators of the MBB.
1829+
auto CheckIfMBBNonFirstTerminators = [](MachineInstr &MI) {
1830+
if (!MI.isTerminator())
1831+
return false;
1832+
return MI.getParent()->getFirstTerminator() != &MI;
1833+
};
1834+
if (ForceEmitZeroFlag && !CheckIfMBBNonFirstTerminators(MI))
18281835
Wait = WCG->getAllZeroWaitcnt(/*IncludeVSCnt=*/false);
18291836

18301837
if (ForceEmitWaitcnt[LOAD_CNT])
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# RUN: llc -mtriple=amdgcn-amd-amdhsa -run-pass si-insert-waitcnts -amdgpu-waitcnt-forcezero=1 %s -o - | FileCheck %s
2+
3+
...
4+
5+
# CHECK-LABEL: waitcnt-debug-non-first-terminators
6+
# CHECK: S_WAITCNT 0
7+
# CHECK-NEXT: S_CBRANCH_SCC1 %bb.1, implicit $scc
8+
# CHECK-NEXT: S_BRANCH %bb.2, implicit $scc
9+
10+
name: waitcnt-debug-non-first-terminators
11+
liveins:
12+
machineFunctionInfo:
13+
isEntryFunction: true
14+
body: |
15+
bb.0:
16+
S_CBRANCH_SCC1 %bb.1, implicit $scc
17+
S_BRANCH %bb.2, implicit $scc
18+
bb.1:
19+
S_NOP 0
20+
bb.2:
21+
S_NOP 0
22+
...

0 commit comments

Comments
 (0)