1 ; RUN: opt %s -jump-threading -S | FileCheck %s
7 define i32 @test1(i1 %cond) {
10 br i1 %cond, label %T1, label %F1
21 %A = phi i1 [true, %T1], [false, %F1]
22 %B = phi i32 [%v1, %T1], [%v2, %F1]
23 br i1 %A, label %T2, label %F2
38 ;; cond is known false on Entry -> F1 edge!
39 define i32 @test2(i1 %cond) {
42 br i1 %cond, label %T1, label %F1
45 ; CHECK: %v1 = call i32 @f1()
51 br i1 %cond, label %Merge, label %F2
54 %B = phi i32 [47, %T1], [192, %F1]
64 define i32 @test3(i1 %cond) {
67 ; CHECK-NEXT: ret i32 42
68 br i1 undef, label %T1, label %F1
77 define i32 @test4(i1 %cond, i1 %cond2) {
80 br i1 %cond, label %T1, label %F1
83 ; CHECK: %v1 = call i32 @f1()
84 ; CHECK-NEXT: br label %T
91 ; CHECK: %v2 = call i32 @f2()
92 ; CHECK-NEXT: br i1 %cond2,
96 %A = phi i1 [undef, %T1], [%cond2, %F1]
97 %B = phi i32 [%v1, %T1], [%v2, %F1]
98 br i1 %A, label %T2, label %F2
109 ;; This tests that the branch in 'merge' can be cloned up into T1.
110 define i32 @test5(i1 %cond, i1 %cond2) {
113 br i1 %cond, label %T1, label %F1
117 ; CHECK-NEXT: %v1 = call i32 @f1()
118 ; CHECK-NEXT: %cond3 = icmp eq i32 %v1, 412
119 ; CHECK-NEXT: br i1 %cond3, label %T2, label %F2
122 %cond3 = icmp eq i32 %v1, 412
130 %A = phi i1 [%cond3, %T1], [%cond2, %F1]
131 %B = phi i32 [%v1, %T1], [%v2, %F1]
132 br i1 %A, label %T2, label %F2
143 ;; Lexically duplicated conditionals should be threaded.
146 define i32 @test6(i32 %A) {
148 %tmp455 = icmp eq i32 %A, 42
149 br i1 %tmp455, label %BB1, label %BB2
151 ; CHECK: call i32 @f2()
152 ; CHECK-NEXT: ret i32 3
154 ; CHECK: call i32 @f1()
156 ; CHECK: call void @f3()
166 %tmp459 = icmp eq i32 %A, 42
167 br i1 %tmp459, label %BB3, label %BB4
179 ;; This tests that the branch in 'merge' can be cloned up into T1.
181 define i32 @test7(i1 %cond, i1 %cond2) {
185 br i1 %cond, label %Merge, label %F1
192 %B = phi i32 [%v1, %Entry], [%v2, %F1]
193 %M = icmp ne i32 %B, %v1
194 %N = icmp eq i32 %B, 47
196 br i1 %O, label %T2, label %F2
200 ; CHECK-NEXT: %v2 = call i32 @f2()
209 ; CHECK-NEXT: phi i32
215 define i32 @test8b(i1 %cond, i1 %cond2) {
218 %A = call i1 @test8a()
219 br i1 %A, label %T1, label %F1
223 ; CHECK-NEXT: br i1 %A, label %T1, label %Y
226 %B = call i1 @test8a()
227 br i1 %B, label %T2, label %F1
231 ; CHECK-NEXT: br i1 %B, label %T2, label %Y
233 %C = call i1 @test8a()
234 br i1 %cond, label %T3, label %F1
238 ; CHECK-NEXT: br i1 %cond, label %T3, label %Y
243 %D = phi i32 [0, %T0], [0, %T1], [1, %T2]
244 %E = icmp eq i32 %D, 1
245 %F = and i1 %E, %cond
246 br i1 %F, label %X, label %Y
255 ;;; Verify that we can handle constraint propagation through "xor x, 1".
256 define i32 @test9(i1 %cond, i1 %cond2) {
260 br i1 %cond, label %Merge, label %F1
263 ; CHECK-NEXT: %v1 = call i32 @f1()
264 ; CHECK-NEXT: br i1 %cond, label %F2, label %Merge
271 %B = phi i32 [%v1, %Entry], [%v2, %F1]
272 %M = icmp eq i32 %B, %v1
274 %N = icmp eq i32 %B, 47
276 br i1 %O, label %T2, label %F2
280 ; CHECK-NEXT: %v2 = call i32 @f2()
283 %Q = zext i1 %M to i32
289 ; CHECK-NEXT: phi i32
295 declare i32 @test10f1()
296 declare i32 @test10f2()
297 declare void @test10f3()
299 ;; Non-local condition threading.
300 define i32 @test10g(i1 %cond) {
302 ; CHECK-NEXT: br i1 %cond, label %T2, label %F2
303 br i1 %cond, label %T1, label %F1
306 %v1 = call i32 @test10f1()
309 ; CHECK: %v1 = call i32 @test10f1()
310 ; CHECK-NEXT: call void @f3()
311 ; CHECK-NEXT: ret i32 %v1
314 %v2 = call i32 @test10f2()
318 %B = phi i32 [%v1, %T1], [%v2, %F1]
319 br i1 %cond, label %T2, label %F2
330 ; Impossible conditional constraints should get threaded. BB3 is dead here.
331 define i32 @test11(i32 %A) {
334 ; CHECK-NEXT: br i1 %tmp455, label %BB4, label %BB2
335 %tmp455 = icmp eq i32 %A, 42
336 br i1 %tmp455, label %BB1, label %BB2
339 ; CHECK: call i32 @f1()
340 ; CHECK-NEXT: ret i32 %C
346 %tmp459 = icmp eq i32 %A, 43
347 br i1 %tmp459, label %BB3, label %BB4
358 ;; Correlated value through boolean expression. GCC PR18046.
359 define void @test12(i32 %A) {
362 %cond = icmp eq i32 %A, 0
363 br i1 %cond, label %bb, label %bb1
364 ; Should branch to the return block instead of through BB1.
366 ; CHECK-NEXT: %cond = icmp eq i32 %A, 0
367 ; CHECK-NEXT: br i1 %cond, label %bb1, label %return
370 %B = call i32 @test10f2()
374 %C = phi i32 [ %A, %entry ], [ %B, %bb ]
375 %cond4 = icmp eq i32 %C, 0
376 br i1 %cond4, label %bb2, label %return
379 ; CHECK-NEXT: %B = call i32 @test10f2()
380 ; CHECK-NEXT: %cond4 = icmp eq i32 %B, 0
381 ; CHECK-NEXT: br i1 %cond4, label %bb2, label %return
384 %D = call i32 @test10f2()
392 ;; Duplicate condition to avoid xor of cond.
394 define i32 @test13(i1 %cond, i1 %cond2) {
398 br i1 %cond, label %Merge, label %F1
404 %B = phi i1 [true, %Entry], [%cond2, %F1]
405 %C = phi i32 [192, %Entry], [%v1, %F1]
406 %M = icmp eq i32 %C, 192
408 br i1 %N, label %T2, label %F2
416 ; CHECK: br i1 %cond, label %F2, label %Merge
419 ; CHECK-NEXT: %M = icmp eq i32 %v1, 192
420 ; CHECK-NEXT: %N = xor i1 %cond2, %M
421 ; CHECK-NEXT: br i1 %N, label %T2, label %F2
425 define i32 @test14(i32 %in) {
427 %A = icmp eq i32 %in, 0
428 ; CHECK: br i1 %A, label %right_ret, label %merge
429 br i1 %A, label %left, label %right
441 ; CHECK-NOT: %C = phi i32 [%in, %left], [%B, %right]
442 %C = phi i32 [%in, %left], [%B, %right]
444 %E = icmp eq i32 %D, 2
445 br i1 %E, label %left_ret, label %right_ret
457 define i32 @test15(i32 %len) {
459 ; CHECK: icmp ult i32 %len, 13
460 %tmp = icmp ult i32 %len, 13
461 br i1 %tmp, label %check, label %exit0
467 %tmp9 = icmp ult i32 %len, 21
468 br i1 %tmp9, label %exit1, label %exit2
471 ; CHECK-NOT: ret i32 2