Skip to content

Commit 5cd7d81

Browse files
authored
[llvm-reduce] Treat CallBrInst as Branch (#156366)
Fixes the bug of the missing terminator for CallBrInst.
1 parent 3219fb0 commit 5cd7d81

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
; RUN: llvm-reduce %s -o %t --abort-on-invalid-reduction --delta-passes=basic-blocks --test FileCheck --test-arg %s --test-arg --check-prefix=INTERESTING --test-arg --input-file
2+
; RUN: FileCheck %s --input-file %t --check-prefixes=CHECK,INTERESTING
3+
4+
5+
; CHECK-LABEL: define i32 @keep_callbr(ptr %p, i1 %cond) {
6+
; CHECK: entry1:
7+
; CHECK-NEXT: callbr void asm
8+
; INTERESTING: store i32 0,
9+
; INTERESTING: store i32 1,
10+
11+
define i32 @keep_callbr(ptr %p, i1 %cond) {
12+
entry1:
13+
callbr void asm sideeffect "", "!i,~{dirflag},~{fpsr},~{flags}"()
14+
to label %for.cond [label %preheader]
15+
16+
for.cond:
17+
store i32 0, ptr %p
18+
ret i32 0
19+
20+
preheader:
21+
store i32 1, ptr %p
22+
ret i32 1
23+
}
24+
25+
26+
; CHECK-LABEL: define i32 @drop_callbr(ptr %p, i1 %cond) {
27+
; CHECK: entry1:
28+
; CHECK-NEXT: br
29+
; INTERESTING: store i32 0,
30+
31+
define i32 @drop_callbr(ptr %p, i1 %cond) {
32+
entry1:
33+
callbr void asm sideeffect "", "!i,~{dirflag},~{fpsr},~{flags}"()
34+
to label %for.cond [label %preheader]
35+
36+
for.cond:
37+
store i32 0, ptr %p
38+
ret i32 0
39+
40+
preheader:
41+
store i32 1, ptr %p
42+
ret i32 1
43+
44+
}

llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static void replaceBranchTerminator(BasicBlock &BB,
4949
if (isa<CatchSwitchInst>(Term))
5050
return;
5151

52-
bool IsBranch = isa<BranchInst>(Term);
52+
bool IsBranch = isa<BranchInst>(Term) || isa<CallBrInst>(Term);
5353
if (InvokeInst *Invoke = dyn_cast<InvokeInst>(Term)) {
5454
BasicBlock *UnwindDest = Invoke->getUnwindDest();
5555
BasicBlock::iterator LP = UnwindDest->getFirstNonPHIIt();

0 commit comments

Comments
 (0)