1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -ipsccp < %s | FileCheck %s
7 ; Make sure we can eliminate what is in BB0 as we know that the indirectbr is going to BB1.
9 define void @indbrtest1() {
10 ; CHECK-LABEL: @indbrtest1(
12 ; CHECK-NEXT: br label [[BB1:%.*]]
14 ; CHECK-NEXT: call void @BB1_f()
15 ; CHECK-NEXT: ret void
18 indirectbr i8* blockaddress(@indbrtest1, %BB1), [label %BB0, label %BB1]
27 ; Make sure we can eliminate what is in BB0 as we know that the indirectbr is going to BB1
28 ; by looking through the casts. The casts should be folded away when they are visited
29 ; before the indirectbr instruction.
31 define void @indbrtest2() {
32 ; CHECK-LABEL: @indbrtest2(
34 ; CHECK-NEXT: br label [[BB1:%.*]]
36 ; CHECK-NEXT: call void @BB1_f()
37 ; CHECK-NEXT: ret void
40 %a = ptrtoint i8* blockaddress(@indbrtest2, %BB1) to i64
41 %b = inttoptr i64 %a to i8*
42 %c = bitcast i8* %b to i8*
43 indirectbr i8* %b, [label %BB0, label %BB1]
52 ; Make sure we can not eliminate BB0 as we do not know the target of the indirectbr.
54 define void @indbrtest3(i8** %Q) {
55 ; CHECK-LABEL: @indbrtest3(
57 ; CHECK-NEXT: [[T:%.*]] = load i8*, i8** [[Q:%.*]], align 8
58 ; CHECK-NEXT: indirectbr i8* [[T]], [label [[BB0:%.*]], label %BB1]
60 ; CHECK-NEXT: call void @BB0_f()
61 ; CHECK-NEXT: br label [[BB1:%.*]]
63 ; CHECK-NEXT: call void @BB1_f()
64 ; CHECK-NEXT: ret void
67 %t = load i8*, i8** %Q
68 indirectbr i8* %t, [label %BB0, label %BB1]
77 ; Make sure we eliminate BB1 as we pick the first successor on undef.
79 define void @indbrtest4(i8** %Q) {
80 ; CHECK-LABEL: @indbrtest4(
82 ; CHECK-NEXT: br label [[BB0:%.*]]
84 ; CHECK-NEXT: call void @BB0_f()
85 ; CHECK-NEXT: ret void
88 indirectbr i8* undef, [label %BB0, label %BB1]
97 define internal i32 @indbrtest5(i1 %c) {
98 ; CHECK-LABEL: @indbrtest5(
100 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
102 ; CHECK-NEXT: br label [[BRANCH_BLOCK:%.*]]
104 ; CHECK-NEXT: br label [[BRANCH_BLOCK]]
105 ; CHECK: branch.block:
106 ; CHECK-NEXT: [[ADDR:%.*]] = phi i8* [ blockaddress(@indbrtest5, [[TARGET1:%.*]]), [[BB1]] ], [ blockaddress(@indbrtest5, [[TARGET2:%.*]]), [[BB2]] ]
107 ; CHECK-NEXT: indirectbr i8* [[ADDR]], [label [[TARGET1]], label %target2]
109 ; CHECK-NEXT: br label [[TARGET2]]
111 ; CHECK-NEXT: ret i32 undef
114 br i1 %c, label %bb1, label %bb2
117 br label %branch.block
121 br label %branch.block
124 %addr = phi i8* [blockaddress(@indbrtest5, %target1), %bb1], [blockaddress(@indbrtest5, %target2), %bb2]
125 indirectbr i8* %addr, [label %target1, label %target2]
135 define i32 @indbrtest5_callee(i1 %c) {
136 ; CHECK-LABEL: @indbrtest5_callee(
137 ; CHECK-NEXT: [[R:%.*]] = call i32 @indbrtest5(i1 [[C:%.*]])
138 ; CHECK-NEXT: ret i32 10
140 %r = call i32 @indbrtest5(i1 %c)
144 define i32 @indbr_duplicate_successors_phi(i1 %c, i32 %x) {
145 ; CHECK-LABEL: @indbr_duplicate_successors_phi(
147 ; CHECK-NEXT: br i1 [[C:%.*]], label [[INDBR:%.*]], label [[BB0:%.*]]
149 ; CHECK-NEXT: br label [[BB0]]
151 ; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ [[X:%.*]], [[ENTRY:%.*]] ], [ 0, [[INDBR]] ]
152 ; CHECK-NEXT: ret i32 [[PHI]]
155 br i1 %c, label %indbr, label %BB0
158 indirectbr i8* blockaddress(@indbr_duplicate_successors_phi, %BB0), [label %BB0, label %BB0, label %BB1]
161 %phi = phi i32 [ %x, %entry ], [ 0, %indbr ], [ 0, %indbr ]