1 ; RUN: opt -S -jump-threading %s | FileCheck %s
3 ; Value of predicate known on all inputs (trivial case)
4 ; Note: InstCombine/EarlyCSE would also get this case
5 define void @test(i8* %p, i8** %addr) {
8 %cmp0 = icmp eq i8* %p, null
9 br i1 %cmp0, label %exit, label %loop
13 ; CHECK-NEXT: br label %loop
14 %p1 = phi i8* [%p, %entry], [%p1, %loop]
15 %cmp1 = icmp eq i8* %p1, null
16 br i1 %cmp1, label %exit, label %loop
21 ; Value of predicate known on all inputs (non-trivial)
22 define void @test2(i8* %p) {
25 %cmp0 = icmp eq i8* %p, null
26 br i1 %cmp0, label %exit, label %loop
28 %p1 = phi i8* [%p, %entry], [%p2, %backedge]
29 %cmp1 = icmp eq i8* %p1, null
30 br i1 %cmp1, label %exit, label %backedge
32 ; CHECK-LABEL: backedge:
38 ; CHECK-DAG: label %backedge
39 %addr = bitcast i8* %p1 to i8**
40 %p2 = load i8*, i8** %addr
41 %cmp2 = icmp eq i8* %p2, null
42 br i1 %cmp2, label %exit, label %loop
47 ; If the inputs don't branch the same way, we can't rewrite
48 ; Well, we could unroll this loop exactly twice, but that's
49 ; a different transform.
50 define void @test_mixed(i8* %p) {
51 ; CHECK-LABEL: @test_mixed
53 %cmp0 = icmp eq i8* %p, null
54 br i1 %cmp0, label %exit, label %loop
58 ; CHECK-NEXT: %cmp1 = icmp
59 ; CHECK-NEXT: br i1 %cmp1
60 %p1 = phi i8* [%p, %entry], [%p1, %loop]
61 %cmp1 = icmp ne i8* %p1, null
62 br i1 %cmp1, label %exit, label %loop
67 ; The eq predicate is always true if we go through the path from
68 ; L1 to L3, no matter the phi result %t5 is on the lhs or rhs of
73 define void @test3(i32 %m, i32** %t1) {
76 %t2 = load i32*, i32** %t1, align 8
78 ; CHECK: %t3 = icmp eq i32* %t2, null
79 ; CHECK: br i1 %t3, label %[[LABEL2:.*]], label %[[LABEL1:.*]]
81 %t3 = icmp eq i32* %t2, null
82 br i1 %t3, label %L3, label %L2
85 ; CHECK-NEXT: %t4 = load i32, i32* %t2, align 4
87 %t4 = load i32, i32* %t2, align 4
91 %t5 = phi i32 [ %t0, %L1 ], [ %t4, %L2 ]
92 %t6 = icmp eq i32 %t0, %t5
93 br i1 %t6, label %L4, label %L5
96 ; CHECK-NEXT: call void @goo()