Skip to content

Commit 3ea2f69

Browse files
committed
[GVN] Check IndirectBr in Predecessor Terminators
Critical edges with an IndirectBr terminator cannot be split. Add a check it to prevent assertion failures. Fixes : #150229
1 parent f79efa9 commit 3ea2f69

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

llvm/lib/Transforms/Scalar/GVN.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3297,8 +3297,10 @@ void GVNPass::addDeadBlock(BasicBlock *BB) {
32973297
if (!DeadBlocks.count(P))
32983298
continue;
32993299

3300+
auto PredTerminator = P->getTerminator();
33003301
if (is_contained(successors(P), B) &&
3301-
isCriticalEdge(P->getTerminator(), B)) {
3302+
!isa<IndirectBrInst>(PredTerminator) &&
3303+
isCriticalEdge(PredTerminator, B)) {
33023304
if (BasicBlock *S = splitCriticalEdges(P, B))
33033305
DeadBlocks.insert(P = S);
33043306
}

llvm/test/Transforms/GVN/cond_br.ll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,22 @@ if.end: ; preds = %if.else, %if.then
5353
}
5454

5555
declare void @bar(i32)
56+
57+
define void @indirectbr_could_not_split() {
58+
; CHECK-LABEL: define void @indirectbr_could_not_split() {
59+
; CHECK-NEXT: [[ENTRY:.*:]]
60+
; CHECK-NEXT: br i1 false, label %[[IBR:.*]], label %[[EXIT:.*]]
61+
; CHECK: [[IBR]]:
62+
; CHECK-NEXT: indirectbr ptr null, [label %[[EXIT]], label %exit]
63+
; CHECK: [[EXIT]]:
64+
; CHECK-NEXT: ret void
65+
;
66+
entry:
67+
br i1 false, label %ibr, label %exit
68+
69+
ibr:
70+
indirectbr ptr null, [label %exit, label %exit]
71+
72+
exit:
73+
ret void
74+
}

0 commit comments

Comments
 (0)