Skip to content

Commit a750fcb

Browse files
authored
[GVN] Check IndirectBr in Predecessor Terminators (#151188)
Critical edges with an IndirectBr terminator cannot be split. Add a check it to prevent assertion failures. Fixes: #150229
1 parent 35bad22 commit a750fcb

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,14 @@ BasicBlock *
111111
llvm::SplitKnownCriticalEdge(Instruction *TI, unsigned SuccNum,
112112
const CriticalEdgeSplittingOptions &Options,
113113
const Twine &BBName) {
114-
assert(!isa<IndirectBrInst>(TI) &&
115-
"Cannot split critical edge from IndirectBrInst");
116-
117114
BasicBlock *TIBB = TI->getParent();
118115
BasicBlock *DestBB = TI->getSuccessor(SuccNum);
119116

120-
// Splitting the critical edge to a pad block is non-trivial. Don't do
121-
// it in this generic function.
122-
if (DestBB->isEHPad()) return nullptr;
117+
// Splitting the critical edge to a pad block is non-trivial.
118+
// And we cannot split block with IndirectBr as a terminator.
119+
// Don't do it in this generic function.
120+
if (DestBB->isEHPad() || isa<IndirectBrInst>(TI))
121+
return nullptr;
123122

124123
if (Options.IgnoreUnreachableDests &&
125124
isa<UnreachableInst>(DestBB->getFirstNonPHIOrDbgOrLifetime()))

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)