Skip to content

Commit da0fe2a

Browse files
isanbardzmodem
authored andcommitted
Filter callbr insts from critical edge splitting
Similarly to how splitting predecessors with an indirectbr isn't handled in the generic way, we also shouldn't split callbrs, for similar reasons. (cherry picked from commit 2fe4576)
1 parent d75ce45 commit da0fe2a

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

llvm/lib/Transforms/Scalar/LICM.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,8 @@ static bool canSplitPredecessors(PHINode *PN, LoopSafetyInfo *SafetyInfo) {
15371537
return false;
15381538
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
15391539
BasicBlock *BBPred = *PI;
1540-
if (isa<IndirectBrInst>(BBPred->getTerminator()))
1540+
if (isa<IndirectBrInst>(BBPred->getTerminator()) ||
1541+
isa<CallBrInst>(BBPred->getTerminator()))
15411542
return false;
15421543
}
15431544
return true;

llvm/lib/Transforms/Utils/BasicBlockUtils.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,8 @@ llvm::SplitAllCriticalEdges(Function &F,
505505
unsigned NumBroken = 0;
506506
for (BasicBlock &BB : F) {
507507
Instruction *TI = BB.getTerminator();
508-
if (TI->getNumSuccessors() > 1 && !isa<IndirectBrInst>(TI))
508+
if (TI->getNumSuccessors() > 1 && !isa<IndirectBrInst>(TI) &&
509+
!isa<CallBrInst>(TI))
509510
for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
510511
if (SplitCriticalEdge(TI, i, Options))
511512
++NumBroken;
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; RUN: opt -licm -disable-output < %s
2+
3+
define i32 @j() {
4+
entry:
5+
br label %for.cond
6+
7+
for.cond: ; preds = %cond.true.i, %entry
8+
callbr void asm sideeffect "", "X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@j, %for.end))
9+
to label %cond.true.i [label %for.end]
10+
11+
cond.true.i: ; preds = %for.cond
12+
%asmresult1.i.i = extractvalue { i8, i32 } zeroinitializer, 1
13+
br i1 undef, label %for.end, label %for.cond
14+
15+
for.end: ; preds = %cond.true.i, %for.cond
16+
%asmresult1.i.i2 = phi i32 [ %asmresult1.i.i, %cond.true.i ], [ undef, %for.cond ]
17+
ret i32 undef
18+
}

0 commit comments

Comments
 (0)