1 ; RUN: opt -S -passes=jump-threading,verify < %s | FileCheck %s
9 ; Make sure we update the phi node properly.
11 ; CHECK-LABEL: define void @test_br_folding_not_threading_update_phi(
13 ; Make sure we update the phi node properly here, i.e. we only have 2 predecessors, entry and L0
14 ; CHECK: %res.0 = phi i32 [ 0, %L0 ], [ 1, %entry ]
15 define void @test_br_folding_not_threading_update_phi(i32 %val) nounwind {
17 %cmp = icmp eq i32 %val, 32
18 br i1 %cmp, label %L0, label %L1
33 switch i32 %val, label %L2 [
39 %res.0 = phi i32 [ 0, %L0 ], [ 0, %L0 ], [1, %entry]
40 call void @f4(i32 %res.0)
47 ; Make sure we can fold this branch ... We will not be able to thread it as
48 ; L0 is too big to duplicate. L2 is the unreachable block here.
50 ; CHECK-LABEL: @test_br_folding_not_threading(
52 ; CHECK: call i32 @f2()
53 ; CHECK: call void @f3()
54 ; CHECK-NEXT: ret void
57 define void @test_br_folding_not_threading(i1 %cond) nounwind {
59 br i1 %cond, label %L0, label %L3
74 br i1 %cond, label %L1, label %L2
88 ; Make sure we can fold this branch ... We will not be able to thread it as
89 ; L0 is too big to duplicate. L2 is the unreachable block here.
90 ; With more than 1 predecessors.
92 ; CHECK-LABEL: @test_br_folding_not_threading_multiple_preds(
94 ; CHECK: call i32 @f2()
95 ; CHECK: call void @f3()
96 ; CHECK-NEXT: ret void
99 define void @test_br_folding_not_threading_multiple_preds(i1 %condx, i1 %cond) nounwind {
101 br i1 %condx, label %X0, label %X1
104 br i1 %cond, label %L0, label %L3
107 br i1 %cond, label %L0, label %L3
123 br i1 %cond, label %L1, label %L2
136 ; Make sure we can do the RAUW for %add...
138 ; CHECK-LABEL: @rauw_if_possible(
139 ; CHECK: call void @f4(i32 96)
140 define void @rauw_if_possible(i32 %value) nounwind {
142 %cmp = icmp eq i32 %value, 32
143 br i1 %cmp, label %L0, label %L3
147 %add = add i32 %value, 64
148 switch i32 %add, label %L3 [
157 call void @f4(i32 %add)
164 ; Make sure we can NOT do the RAUW for %add...
166 ; CHECK-LABEL: @rauw_if_possible2(
167 ; CHECK: call void @f4(i32 %add)
168 define void @rauw_if_possible2(i32 %value) nounwind {
170 %cmp = icmp eq i32 %value, 32
171 %add = add i32 %value, 64
172 br i1 %cmp, label %L0, label %L2
176 switch i32 %add, label %L3 [
185 call void @f4(i32 %add)
192 ; Make sure we can fold this branch ... We will not be able to thread it as
193 ; L0 is too big to duplicate.
194 ; We do not attempt to rewrite the indirectbr target here, but we still take
195 ; its target after L0 into account and that enables us to fold.
197 ; L2 is the unreachable block here.
199 ; CHECK-LABEL: @test_br_folding_not_threading_indirect_branch(
201 ; CHECK: call i32 @f2()
202 ; CHECK: call void @f3()
203 ; CHECK-NEXT: ret void
206 define void @test_br_folding_not_threading_indirect_branch(i1 %condx, i1 %cond) nounwind {
208 br i1 %condx, label %X0, label %X1
211 br i1 %cond, label %L0, label %L3
214 br i1 %cond, label %XX1, label %L3
217 indirectbr ptr blockaddress(@test_br_folding_not_threading_indirect_branch, %L0), [label %L0]
233 br i1 %cond, label %L1, label %L2