Skip to content

Commit 8cb652b

Browse files
committed
Merging r368873:
------------------------------------------------------------------------ r368873 | void | 2019-08-14 18:44:07 +0200 (Wed, 14 Aug 2019) | 15 lines Ignore indirect branches from callbr. Summary: We can't speculate around indirect branches: indirectbr and invoke. The callbr instruction needs to be included here. Reviewers: nickdesaulniers, manojgupta, chandlerc Reviewed By: chandlerc Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66200 ------------------------------------------------------------------------ llvm-svn: 369085
1 parent 450f5f3 commit 8cb652b

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

llvm/lib/Transforms/Scalar/SpeculateAroundPHIs.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,10 @@ static bool tryToSpeculatePHIs(SmallVectorImpl<PHINode *> &PNs,
777777
// speculation if the predecessor is an invoke. This doesn't seem
778778
// fundamental and we should probably be splitting critical edges
779779
// differently.
780-
if (isa<IndirectBrInst>(PredBB->getTerminator()) ||
781-
isa<InvokeInst>(PredBB->getTerminator())) {
780+
const auto *TermInst = PredBB->getTerminator();
781+
if (isa<IndirectBrInst>(TermInst) ||
782+
isa<InvokeInst>(TermInst) ||
783+
isa<CallBrInst>(TermInst)) {
782784
LLVM_DEBUG(dbgs() << " Invalid: predecessor terminator: "
783785
<< PredBB->getName() << "\n");
784786
return false;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
; RUN: opt -S -passes=spec-phis %s
2+
3+
; This testcase crashes during the speculate around PHIs pass. The pass however
4+
; results in no changes.
5+
6+
define i32 @test1() {
7+
entry:
8+
callbr void asm sideeffect "", "X,X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@test1, %return), i8* blockaddress(@test1, %f))
9+
to label %asm.fallthrough [label %return, label %f]
10+
11+
asm.fallthrough:
12+
br label %return
13+
14+
f:
15+
br label %return
16+
17+
return:
18+
%retval.0 = phi i32 [ 0, %f ], [ 1, %asm.fallthrough ], [ 1, %entry ]
19+
ret i32 %retval.0
20+
}
21+
22+
define void @test2() {
23+
entry:
24+
br label %tailrecurse
25+
26+
tailrecurse:
27+
%call = tail call i32 @test3()
28+
%tobool1 = icmp eq i32 %call, 0
29+
callbr void asm sideeffect "", "X,X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@test2, %test1.exit), i8* blockaddress(@test2, %f.i))
30+
to label %if.end6 [label %test1.exit, label %f.i]
31+
32+
f.i:
33+
br label %test1.exit
34+
35+
test1.exit:
36+
%retval.0.i = phi i1 [ false, %f.i ], [ true, %tailrecurse ]
37+
%brmerge = or i1 %tobool1, %retval.0.i
38+
br i1 %brmerge, label %if.end6, label %tailrecurse
39+
40+
if.end6:
41+
ret void
42+
}
43+
44+
declare i32 @test3()

0 commit comments

Comments
 (0)