Skip to content

Commit 37aa16e

Browse files
committed
[DA] Don't propagate from unreachable blocks
Summary: Fixes crash that could occur when a divergent terminator has an unreachable parent. Reviewers: rampitec, nhaehnle, arsenm Subscribers: jvesely, wdng, hiraditya, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D73323
1 parent 5dda92f commit 37aa16e

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

llvm/lib/Analysis/DivergenceAnalysis.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ void DivergenceAnalysis::propagateBranchDivergence(const Instruction &Term) {
301301

302302
markDivergent(Term);
303303

304+
// Don't propagate divergence from unreachable blocks.
305+
if (!DT.isReachableFromEntry(Term.getParent()))
306+
return;
307+
304308
const auto *BranchLoop = LI.getLoopFor(Term.getParent());
305309

306310
// whether there is a divergent loop exit from BranchLoop (if any)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; RUN: opt %s -mtriple amdgcn-- -analyze -divergence -use-gpu-divergence-analysis | FileCheck %s
2+
3+
; CHECK: DIVERGENT: %tmp = cmpxchg volatile
4+
define amdgpu_kernel void @unreachable_loop(i32 %tidx) #0 {
5+
entry:
6+
unreachable
7+
8+
unreachable_loop: ; preds = %do.body.i, %if.then11
9+
%tmp = cmpxchg volatile i32 addrspace(1)* null, i32 0, i32 0 seq_cst seq_cst
10+
%cmp.i = extractvalue { i32, i1 } %tmp, 1
11+
br i1 %cmp.i, label %unreachable_loop, label %end
12+
13+
end: ; preds = %do.body.i51, %atomicAdd_g_f.exit
14+
unreachable
15+
}
16+
17+
attributes #0 = { norecurse nounwind }

0 commit comments

Comments
 (0)