Skip to content

Commit 913837e

Browse files
committed
[ScheduleDAG] Fix removing edges with weak deps
In SUnit::removePred edges are removed from the Preds and Succs lists before updating the bookkeeping. This could result in incorrect values for NumPreds/SuccsLeft and cause WeakPreds/SuccsLeft to underflow, since the incorrect SDep will be used to update these values. Reviewed By: rampitec Differential Revision: https://reviews.llvm.org/D142325
1 parent a253a0b commit 913837e

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

llvm/lib/CodeGen/ScheduleDAG.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ void SUnit::removePred(const SDep &D) {
183183
SUnit *N = D.getSUnit();
184184
SmallVectorImpl<SDep>::iterator Succ = llvm::find(N->Succs, P);
185185
assert(Succ != N->Succs.end() && "Mismatching preds / succs lists!");
186-
N->Succs.erase(Succ);
187-
Preds.erase(I);
188186
// Update the bookkeeping.
189187
if (P.getKind() == SDep::Data) {
190188
assert(NumPreds > 0 && "NumPreds will underflow!");
@@ -193,21 +191,25 @@ void SUnit::removePred(const SDep &D) {
193191
--N->NumSuccs;
194192
}
195193
if (!N->isScheduled) {
196-
if (D.isWeak())
194+
if (D.isWeak()) {
195+
assert(WeakPredsLeft > 0 && "WeakPredsLeft will underflow!");
197196
--WeakPredsLeft;
198-
else {
197+
} else {
199198
assert(NumPredsLeft > 0 && "NumPredsLeft will underflow!");
200199
--NumPredsLeft;
201200
}
202201
}
203202
if (!isScheduled) {
204-
if (D.isWeak())
203+
if (D.isWeak()) {
204+
assert(WeakSuccsLeft > 0 && "WeakSuccsLeft will underflow!");
205205
--N->WeakSuccsLeft;
206-
else {
206+
} else {
207207
assert(N->NumSuccsLeft > 0 && "NumSuccsLeft will underflow!");
208208
--N->NumSuccsLeft;
209209
}
210210
}
211+
N->Succs.erase(Succ);
212+
Preds.erase(I);
211213
if (P.getLatency() != 0) {
212214
this->setDepthDirty();
213215
N->setHeightDirty();
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -march=amdgcn -mcpu=gfx908 -run-pass=machine-scheduler -verify-misched -o - %s | FileCheck %s
3+
4+
# This would hang after removing edges from the SCHED_BARRIER since the number
5+
# of Preds/Succs would be left in an inconsistent state.
6+
7+
---
8+
name: sched_barrier_cluster_dep_hang
9+
tracksRegLiveness: true
10+
body: |
11+
; CHECK-LABEL: name: sched_barrier_cluster_dep_hang
12+
; CHECK: bb.0:
13+
; CHECK-NEXT: successors: %bb.1(0x80000000)
14+
; CHECK-NEXT: {{ $}}
15+
; CHECK-NEXT: [[DEF:%[0-9]+]]:sreg_64 = IMPLICIT_DEF
16+
; CHECK-NEXT: [[DEF1:%[0-9]+]]:vgpr_32 = IMPLICIT_DEF
17+
; CHECK-NEXT: {{ $}}
18+
; CHECK-NEXT: bb.1:
19+
; CHECK-NEXT: SCHED_BARRIER 128
20+
; CHECK-NEXT: [[GLOBAL_LOAD_DWORD_SADDR:%[0-9]+]]:vgpr_32 = GLOBAL_LOAD_DWORD_SADDR [[DEF]], [[DEF1]], 512, 0, implicit $exec :: (load (s32))
21+
; CHECK-NEXT: [[GLOBAL_LOAD_DWORD_SADDR1:%[0-9]+]]:vgpr_32 = GLOBAL_LOAD_DWORD_SADDR [[DEF]], [[DEF1]], 0, 0, implicit $exec :: (load (s32))
22+
; CHECK-NEXT: SCHED_BARRIER 128
23+
; CHECK-NEXT: [[V_MUL_LO_U32_e64_:%[0-9]+]]:vgpr_32 = nsw V_MUL_LO_U32_e64 [[GLOBAL_LOAD_DWORD_SADDR]], [[GLOBAL_LOAD_DWORD_SADDR]], implicit $exec
24+
; CHECK-NEXT: [[V_MUL_LO_U32_e64_1:%[0-9]+]]:vgpr_32 = nsw V_MUL_LO_U32_e64 [[GLOBAL_LOAD_DWORD_SADDR1]], [[GLOBAL_LOAD_DWORD_SADDR1]], implicit $exec
25+
; CHECK-NEXT: GLOBAL_STORE_DWORD_SADDR [[DEF1]], [[V_MUL_LO_U32_e64_]], [[DEF]], 512, 0, implicit $exec :: (store (s32))
26+
; CHECK-NEXT: GLOBAL_STORE_DWORD_SADDR [[DEF1]], [[V_MUL_LO_U32_e64_1]], [[DEF]], 0, 0, implicit $exec :: (store (s32))
27+
; CHECK-NEXT: S_ENDPGM 0
28+
bb.0:
29+
%0:sreg_64 = IMPLICIT_DEF
30+
%1:vgpr_32 = IMPLICIT_DEF
31+
32+
bb.1:
33+
SCHED_BARRIER 128
34+
%3:vgpr_32 = GLOBAL_LOAD_DWORD_SADDR %0, %1, 0, 0, implicit $exec :: (load (s32))
35+
%5:vgpr_32 = GLOBAL_LOAD_DWORD_SADDR %0, %1, 512, 0, implicit $exec :: (load (s32))
36+
SCHED_BARRIER 128
37+
%6:vgpr_32 = nsw V_MUL_LO_U32_e64 %5, %5, implicit $exec
38+
%4:vgpr_32 = nsw V_MUL_LO_U32_e64 %3, %3, implicit $exec
39+
GLOBAL_STORE_DWORD_SADDR %1, %6, %0, 512, 0, implicit $exec :: (store (s32))
40+
GLOBAL_STORE_DWORD_SADDR %1, %4, %0, 0, 0, implicit $exec :: (store (s32))
41+
S_ENDPGM 0
42+
...

0 commit comments

Comments
 (0)