1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=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 ptr 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 ptr blockaddress(@indbrtest2, %BB1) to i64
41 %b = inttoptr i64 %a to ptr
42 indirectbr ptr %b, [label %BB0, label %BB1]
51 ; Make sure we can not eliminate BB0 as we do not know the target of the indirectbr.
53 define void @indbrtest3(ptr %Q) {
54 ; CHECK-LABEL: @indbrtest3(
56 ; CHECK-NEXT: [[T:%.*]] = load ptr, ptr [[Q:%.*]], align 8
57 ; CHECK-NEXT: indirectbr ptr [[T]], [label [[BB0:%.*]], label %BB1]
59 ; CHECK-NEXT: call void @BB0_f()
60 ; CHECK-NEXT: br label [[BB1:%.*]]
62 ; CHECK-NEXT: call void @BB1_f()
63 ; CHECK-NEXT: ret void
67 indirectbr ptr %t, [label %BB0, label %BB1]
76 ; Branch on undef is UB, so we can convert the indirectbr to unreachable.
78 define void @indbrtest4(ptr %Q) {
79 ; CHECK-LABEL: @indbrtest4(
81 ; CHECK-NEXT: unreachable
84 indirectbr ptr undef, [label %BB0, label %BB1]
93 define internal i32 @indbrtest5(i1 %c) {
94 ; CHECK-LABEL: @indbrtest5(
96 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
98 ; CHECK-NEXT: br label [[BRANCH_BLOCK:%.*]]
100 ; CHECK-NEXT: br label [[BRANCH_BLOCK]]
101 ; CHECK: branch.block:
102 ; CHECK-NEXT: [[ADDR:%.*]] = phi ptr [ blockaddress(@indbrtest5, [[TARGET1:%.*]]), [[BB1]] ], [ blockaddress(@indbrtest5, [[TARGET2:%.*]]), [[BB2]] ]
103 ; CHECK-NEXT: indirectbr ptr [[ADDR]], [label [[TARGET1]], label %target2]
105 ; CHECK-NEXT: br label [[TARGET2]]
107 ; CHECK-NEXT: ret i32 poison
110 br i1 %c, label %bb1, label %bb2
113 br label %branch.block
117 br label %branch.block
120 %addr = phi ptr [blockaddress(@indbrtest5, %target1), %bb1], [blockaddress(@indbrtest5, %target2), %bb2]
121 indirectbr ptr %addr, [label %target1, label %target2]
131 define i32 @indbrtest5_callee(i1 %c) {
132 ; CHECK-LABEL: @indbrtest5_callee(
133 ; CHECK-NEXT: [[R:%.*]] = call i32 @indbrtest5(i1 [[C:%.*]])
134 ; CHECK-NEXT: ret i32 10
136 %r = call i32 @indbrtest5(i1 %c)
140 define i32 @indbr_duplicate_successors_phi(i1 %c, i32 %x) {
141 ; CHECK-LABEL: @indbr_duplicate_successors_phi(
143 ; CHECK-NEXT: br i1 [[C:%.*]], label [[INDBR:%.*]], label [[BB0:%.*]]
145 ; CHECK-NEXT: br label [[BB0]]
147 ; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ [[X:%.*]], [[ENTRY:%.*]] ], [ 0, [[INDBR]] ]
148 ; CHECK-NEXT: ret i32 [[PHI]]
151 br i1 %c, label %indbr, label %BB0
154 indirectbr ptr blockaddress(@indbr_duplicate_successors_phi, %BB0), [label %BB0, label %BB0, label %BB1]
157 %phi = phi i32 [ %x, %entry ], [ 0, %indbr ], [ 0, %indbr ]