Skip to content

Commit f88217b

Browse files
committed
[Reg2Mem] Handle CallBr instructions
1 parent 37eb9c9 commit f88217b

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

llvm/lib/Transforms/Utils/DemoteRegToStack.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,12 @@ AllocaInst *llvm::DemoteRegToStack(Instruction &I, bool VolatileLoads,
102102
new StoreInst(&I, Slot, Handler->getFirstInsertionPt());
103103
return Slot;
104104
}
105+
} else if (InvokeInst *II = dyn_cast<InvokeInst>(&I)) {
106+
InsertPt = II->getNormalDest()->getFirstInsertionPt();
107+
} else if (CallBrInst *CBI = dyn_cast<CallBrInst>(&I)) {
108+
InsertPt = CBI->getDefaultDest()->getFirstInsertionPt();
105109
} else {
106-
InvokeInst &II = cast<InvokeInst>(I);
107-
InsertPt = II.getNormalDest()->getFirstInsertionPt();
110+
llvm_unreachable("Unsupported terminator for Reg2Mem");
108111
}
109112

110113
new StoreInst(&I, Slot, InsertPt);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -passes=reg2mem -S < %s | FileCheck %s
3+
4+
define void @crash() {
5+
; CHECK-LABEL: @crash(
6+
; CHECK-NEXT: entry:
7+
; CHECK-NEXT: [[A_REG2MEM:%.*]] = alloca i64, align 8
8+
; CHECK-NEXT: %"reg2mem alloca point" = bitcast i32 0 to i32
9+
; CHECK-NEXT: [[A:%.*]] = callbr i64 asm "", "=r,r,!i"(i64 0)
10+
; CHECK-NEXT: to label [[THEN:%.*]] [label %entry.else_crit_edge]
11+
; CHECK: entry.else_crit_edge:
12+
; CHECK-NEXT: br label [[ELSE:%.*]]
13+
; CHECK: then:
14+
; CHECK-NEXT: store i64 [[A]], ptr [[A_REG2MEM]], align 4
15+
; CHECK-NEXT: [[A_RELOAD:%.*]] = load i64, ptr [[A_REG2MEM]], align 4
16+
; CHECK-NEXT: [[B:%.*]] = inttoptr i64 [[A_RELOAD]] to ptr
17+
; CHECK-NEXT: br label [[ELSE]]
18+
; CHECK: else:
19+
; CHECK-NEXT: ret void
20+
;
21+
entry:
22+
%a = callbr i64 asm "", "=r,r,!i"(i64 0)
23+
to label %then [label %else]
24+
25+
then:
26+
%b = inttoptr i64 %a to ptr
27+
br label %else
28+
29+
else:
30+
ret void
31+
}

0 commit comments

Comments
 (0)