1 ; RUN: opt -S -jump-threading < %s | FileCheck %s
9 ; Jump threading of branch with select as condition.
10 ; Mostly theoretical since instruction combining simplifies all selects of
11 ; booleans where at least one operand is true/false/undef.
13 ; CHECK-LABEL: @test_br(
15 ; CHECK-NEXT: br i1 %cond, label %L1,
16 define void @test_br(i1 %cond, i1 %value) nounwind {
18 br i1 %cond, label %L0, label %L3
20 %expr = select i1 %cond, i1 true, i1 %value
21 br i1 %expr, label %L1, label %L2
35 ; Jump threading of switch with select as condition.
37 ; CHECK-LABEL: @test_switch(
39 ; CHECK-NEXT: br i1 %cond, label %L1,
40 define void @test_switch(i1 %cond, i8 %value) nounwind {
42 br i1 %cond, label %L0, label %L4
44 %expr = select i1 %cond, i8 1, i8 %value
45 switch i8 %expr, label %L3 [i8 1, label %L1 i8 2, label %L2]
61 ; Make sure the blocks in the indirectbr test aren't trivially removable as
62 ; successors by taking their addresses.
63 @anchor = constant [3 x i8*] [
64 i8* blockaddress(@test_indirectbr, %L1),
65 i8* blockaddress(@test_indirectbr, %L2),
66 i8* blockaddress(@test_indirectbr, %L3)
70 ; Jump threading of indirectbr with select as address.
72 ; CHECK-LABEL: @test_indirectbr(
74 ; CHECK-NEXT: br i1 %cond, label %L1, label %L3
75 define void @test_indirectbr(i1 %cond, i8* %address) nounwind {
77 br i1 %cond, label %L0, label %L3
79 %indirect.goto.dest = select i1 %cond, i8* blockaddress(@test_indirectbr, %L1), i8* %address
80 indirectbr i8* %indirect.goto.dest, [label %L1, label %L2, label %L3]
94 ; Jump threading of indirectbr with select as address. Test increased
95 ; duplication threshold for cases where indirectbr is being threaded
98 ; CHECK-LABEL: @test_indirectbr_thresh(
100 ; CHECK-NEXT: br i1 %cond, label %L1, label %L3
101 ; CHECK-NOT: indirectbr
102 define void @test_indirectbr_thresh(i1 %cond, i8* %address) nounwind {
104 br i1 %cond, label %L0, label %L3
106 %indirect.goto.dest = select i1 %cond, i8* blockaddress(@test_indirectbr_thresh, %L1), i8* %address
110 indirectbr i8* %indirect.goto.dest, [label %L1, label %L2, label %L3]
124 ; A more complicated case: the condition is a select based on a comparison.
126 ; CHECK-LABEL: @test_switch_cmp(
128 ; CHECK-NEXT: br i1 %cond, label %L0, label %[[THREADED:[A-Za-z.0-9]+]]
129 ; CHECK: [[THREADED]]:
130 ; CHECK-NEXT: call void @quux
131 ; CHECK-NEXT: br label %L1
132 define void @test_switch_cmp(i1 %cond, i32 %val, i8 %value) nounwind {
134 br i1 %cond, label %L0, label %L4
136 %val.phi = phi i32 [%val, %entry], [-1, %L4]
137 %cmp = icmp slt i32 %val.phi, 0
138 %expr = select i1 %cmp, i8 1, i8 %value
139 switch i8 %expr, label %L3 [i8 1, label %L1 i8 2, label %L2]
155 ; Make sure the edge value of %0 from entry to L2 includes 0 and L3 is
157 ; CHECK: test_switch_default
161 ; CHECK: [[THREADED:[A-Za-z.0-9]+]]:
166 define void @test_switch_default(i32* nocapture %status) nounwind {
168 %0 = load i32, i32* %status, align 4
169 switch i32 %0, label %L2 [
175 store i32 10025, i32* %status, align 4
179 %1 = load i32, i32* %status, align 4
180 %cmp57.i = icmp eq i32 %1, 0
181 br i1 %cmp57.i, label %L3, label %L4
184 store i32 10000, i32* %status, align 4
191 define void @unfold1(double %x, double %y) nounwind {
193 %sub = fsub double %x, %y
194 %cmp = fcmp ogt double %sub, 1.000000e+01
195 br i1 %cmp, label %cond.end4, label %cond.false
197 cond.false: ; preds = %entry
198 %add = fadd double %x, %y
199 %cmp1 = fcmp ogt double %add, 1.000000e+01
200 %add. = select i1 %cmp1, double %add, double 0.000000e+00
203 cond.end4: ; preds = %entry, %cond.false
204 %cond5 = phi double [ %add., %cond.false ], [ %sub, %entry ]
205 %cmp6 = fcmp oeq double %cond5, 0.000000e+00
206 br i1 %cmp6, label %if.then, label %if.end
208 if.then: ; preds = %cond.end4
212 if.end: ; preds = %if.then, %cond.end4
215 ; CHECK-LABEL: @unfold1
216 ; CHECK: br i1 %cmp, label %cond.end4, label %cond.false
217 ; CHECK: br i1 %cmp1, label %cond.end4, label %if.then
218 ; CHECK: br i1 %cmp6, label %if.then, label %if.end
219 ; CHECK: br label %if.end
223 define void @unfold2(i32 %x, i32 %y) nounwind {
225 %sub = sub nsw i32 %x, %y
226 %cmp = icmp sgt i32 %sub, 10
227 br i1 %cmp, label %cond.end4, label %cond.false
229 cond.false: ; preds = %entry
230 %add = add nsw i32 %x, %y
231 %cmp1 = icmp sgt i32 %add, 10
232 %add. = select i1 %cmp1, i32 0, i32 %add
235 cond.end4: ; preds = %entry, %cond.false
236 %cond5 = phi i32 [ %add., %cond.false ], [ %sub, %entry ]
237 %cmp6 = icmp eq i32 %cond5, 0
238 br i1 %cmp6, label %if.then, label %if.end
240 if.then: ; preds = %cond.end4
244 if.end: ; preds = %if.then, %cond.end4
247 ; CHECK-LABEL: @unfold2
248 ; CHECK: br i1 %cmp, label %if.end, label %cond.false
249 ; CHECK: br i1 %cmp1, label %if.then, label %cond.end4
250 ; CHECK: br i1 %cmp6, label %if.then, label %if.end
251 ; CHECK: br label %if.end
255 define i32 @unfold3(i32 %u, i32 %v, i32 %w, i32 %x, i32 %y, i32 %z, i32 %j) nounwind {
257 %add3 = add nsw i32 %j, 2
258 %cmp.i = icmp slt i32 %u, %v
259 br i1 %cmp.i, label %.exit, label %cond.false.i
261 cond.false.i: ; preds = %entry
262 %cmp4.i = icmp sgt i32 %u, %v
263 br i1 %cmp4.i, label %.exit, label %cond.false.6.i
265 cond.false.6.i: ; preds = %cond.false.i
266 %cmp8.i = icmp slt i32 %w, %x
267 br i1 %cmp8.i, label %.exit, label %cond.false.10.i
269 cond.false.10.i: ; preds = %cond.false.6.i
270 %cmp13.i = icmp sgt i32 %w, %x
271 br i1 %cmp13.i, label %.exit, label %cond.false.15.i
273 cond.false.15.i: ; preds = %cond.false.10.i
274 %phitmp = icmp sge i32 %y, %z
277 .exit: ; preds = %entry, %cond.false.i, %cond.false.6.i, %cond.false.10.i, %cond.false.15.i
278 %cond23.i = phi i1 [ false, %entry ], [ true, %cond.false.i ], [ false, %cond.false.6.i ], [ %phitmp, %cond.false.15.i ], [ true, %cond.false.10.i ]
279 %j.add3 = select i1 %cond23.i, i32 %j, i32 %add3
282 ; CHECK-LABEL: @unfold3
283 ; CHECK: br i1 %cmp.i, label %.exit.thread2, label %cond.false.i
284 ; CHECK: br i1 %cmp4.i, label %.exit.thread, label %cond.false.6.i
285 ; CHECK: br i1 %cmp8.i, label %.exit.thread2, label %cond.false.10.i
286 ; CHECK: br i1 %cmp13.i, label %.exit.thread, label %.exit
287 ; CHECK: br i1 %phitmp, label %.exit.thread, label %.exit.thread2
288 ; CHECK: br label %.exit.thread2