Skip to content

Commit 9eccbc0

Browse files
AlexMacleanbcahoon
authored andcommitted
[LLVM][Uniformity] Fix error causing assert on some irreducible control flow
As the test case demonstrates, it is possible for a block to be identified as a join point while not being the header of a reducible cycle. To address this, when searching for the outermost cycle made divergent by branch outside it, we first check for an irreducible outermost cycle before checking if the parent is reducible. Reviewed By: sameerds Differential Revision: https://reviews.llvm.org/D158014 Change-Id: If510748029b9e4cc06d43a57cccc86cd0cea232d
1 parent 1bd16cf commit 9eccbc0

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

llvm/include/llvm/ADT/GenericUniformityImpl.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -947,11 +947,6 @@ static const CycleT *getExtDivCycle(const CycleT *Cycle,
947947
if (Cycle->contains(DivTermBlock))
948948
return nullptr;
949949

950-
if (Cycle->isReducible()) {
951-
assert(Cycle->getHeader() == JoinBlock);
952-
return nullptr;
953-
}
954-
955950
const auto *Parent = Cycle->getParentCycle();
956951
while (Parent && !Parent->contains(DivTermBlock)) {
957952
// If the join is inside a child, then the parent must be
@@ -962,6 +957,11 @@ static const CycleT *getExtDivCycle(const CycleT *Cycle,
962957
Parent = Cycle->getParentCycle();
963958
}
964959

960+
if (Cycle->isReducible()) {
961+
assert(Cycle->getHeader() == JoinBlock);
962+
return nullptr;
963+
}
964+
965965
LLVM_DEBUG(dbgs() << "cycle made divergent by external branch\n");
966966
return Cycle;
967967
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; RUN: opt %s -passes='print<uniformity>' -disable-output 2>&1 | FileCheck %s
2+
3+
target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
4+
target triple = "nvptx64-nvidia-cuda"
5+
6+
; CHECK: CYCLES ASSSUMED DIVERGENT:
7+
; CHECK-NEXT: depth=1: entries(if.end16 for.cond1) for.body4
8+
9+
define void @foo(i1 %b) {
10+
entry:
11+
br i1 %b, label %if.then, label %if.end16
12+
13+
if.then: ; preds = %entry
14+
br label %for.cond1
15+
16+
for.cond1: ; preds = %if.end16, %for.body4, %if.then
17+
br i1 false, label %for.body4, label %if.end16
18+
19+
for.body4: ; preds = %for.cond1
20+
br label %for.cond1
21+
22+
if.end16: ; preds = %for.cond1, %entry
23+
br label %for.cond1
24+
}

0 commit comments

Comments
 (0)