1 ; RUN: opt -jump-threading -S < %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) {
40 ; CHECK-LABEL: @test2(
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) {
65 ; CHECK-LABEL: @test3(
67 ; CHECK-NEXT: ret i32 42
68 br i1 undef, label %T1, label %F1
77 define i32 @test4(i1 %cond, i1 %cond2) {
78 ; CHECK-LABEL: @test4(
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) {
111 ; CHECK-LABEL: @test5(
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) {
147 ; CHECK-LABEL: @test6(
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) {
183 ; CHECK-LABEL: @test7(
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) {
216 ; CHECK-LABEL: @test8b(
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) {
258 ; CHECK-LABEL: @test9(
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) {
301 ; CHECK-LABEL: @test10g(
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) {
332 ; CHECK-LABEL: @test11(
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) {
360 ; CHECK-LABEL: @test12(
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) {
396 ; CHECK-LABEL: @test13(
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
424 ; CHECK-LABEL: @test14(
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
456 ; CHECK-LABEL: @test15(
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
479 ;;; Verify that we can handle constraint propagation through cast.
480 define i32 @test16(i1 %cond) {
482 ; CHECK-LABEL: @test16(
483 br i1 %cond, label %Merge, label %F1
486 ; CHECK-NEXT: br i1 %cond, label %F2, label %Merge
493 %B = phi i32 [0, %Entry], [%v1, %F1]
494 %M = icmp eq i32 %B, 0
495 %M1 = zext i1 %M to i32
496 %N = icmp eq i32 %M1, 0
497 br i1 %N, label %T2, label %F2
501 ; CHECK-NEXT: %v1 = call i32 @f1()
510 ; CHECK-NEXT: phi i32
513 ; In this test we check that block duplication is inhibited by the presence
514 ; of a function with the 'noduplicate' attribute.
520 ; CHECK-LABEL: define void @h(i32 %p) {
521 define void @h(i32 %p) {
522 %x = icmp ult i32 %p, 5
523 br i1 %x, label %l1, label %l2
534 ; CHECK: call void @g() [[$NOD:#[0-9]+]]
535 ; CHECK-NOT: call void @g() [[$NOD]]
536 call void @g() noduplicate
537 %y = icmp ult i32 %p, 5
538 br i1 %y, label %l4, label %l5
550 define i1 @trunc_switch(i1 %arg) {
551 ; CHECK-LABEL: @trunc_switch
553 ; CHECK: br i1 %arg, label %exitA, label %exitB
554 br i1 %arg, label %common, label %B
560 %phi = phi i8 [ 2, %B ], [ 1, %top ]
561 %trunc = trunc i8 %phi to i2
563 switch i2 %trunc, label %unreach [
578 ; CHECK-LABEL: define void @h_con(i32 %p) {
579 define void @h_con(i32 %p) {
580 %x = icmp ult i32 %p, 5
581 br i1 %x, label %l1, label %l2
592 ; CHECK: call void @g() [[$CON:#[0-9]+]]
593 ; CHECK-NOT: call void @g() [[$CON]]
594 call void @g() convergent
595 %y = icmp ult i32 %p, 5
596 br i1 %y, label %l4, label %l5
609 ; CHECK: attributes [[$NOD]] = { noduplicate }
610 ; CHECK: attributes [[$CON]] = { convergent }