1 ; RUN: opt -jump-threading -S < %s | FileCheck %s
3 declare void @side_effect(i32)
5 define void @test0(i32 %i, i32 %len) {
8 call void @side_effect(i32 0)
9 %i.inc = add nuw i32 %i, 1
10 %c0 = icmp ult i32 %i.inc, %len
11 br i1 %c0, label %left, label %right
15 ; CHECK: br i1 %c0, label %left0, label %right
18 ; CHECK: call void @side_effect
19 ; CHECK-NOT: br i1 %c1
20 ; CHECK: call void @side_effect
21 call void @side_effect(i32 0)
22 %c1 = icmp ult i32 %i, %len
23 br i1 %c1, label %left0, label %right
26 call void @side_effect(i32 0)
30 %t = phi i32 [ 1, %left ], [ 2, %entry ]
31 call void @side_effect(i32 %t)
35 define void @test1(i32 %i, i32 %len) {
36 ; CHECK-LABEL: @test1(
38 call void @side_effect(i32 0)
39 %i.inc = add nsw i32 %i, 1
40 %c0 = icmp slt i32 %i.inc, %len
41 br i1 %c0, label %left, label %right
45 ; CHECK: br i1 %c0, label %left0, label %right
48 ; CHECK: call void @side_effect
49 ; CHECK-NOT: br i1 %c1
50 ; CHECK: call void @side_effect
51 call void @side_effect(i32 0)
52 %c1 = icmp slt i32 %i, %len
53 br i1 %c1, label %left0, label %right
56 call void @side_effect(i32 0)
60 %t = phi i32 [ 1, %left ], [ 2, %entry ]
61 call void @side_effect(i32 %t)
65 define void @test2(i32 %i, i32 %len, i1* %c.ptr) {
66 ; CHECK-LABEL: @test2(
69 ; CHECK: br i1 %c0, label %cont, label %right
71 ; CHECK: br i1 %c, label %left0, label %right
73 ; CHECK: call void @side_effect(i32 0)
74 ; CHECK: call void @side_effect(i32 0)
76 call void @side_effect(i32 0)
77 %i.inc = add nsw i32 %i, 1
78 %c0 = icmp slt i32 %i.inc, %len
79 br i1 %c0, label %cont, label %right
82 %c = load i1, i1* %c.ptr
83 br i1 %c, label %left, label %right
86 call void @side_effect(i32 0)
87 %c1 = icmp slt i32 %i, %len
88 br i1 %c1, label %left0, label %right
91 call void @side_effect(i32 0)
95 %t = phi i32 [ 1, %left ], [ 2, %entry ], [ 3, %cont ]
96 call void @side_effect(i32 %t)
100 ; A s<= B implies A s> B is false.
101 ; CHECK-LABEL: @test3(
103 ; CHECK: br i1 %cmp, label %if.end, label %if.end3
104 ; CHECK-NOT: br i1 %cmp1, label %if.then2, label %if.end
105 ; CHECK-NOT: call void @side_effect(i32 0)
106 ; CHECK: br label %if.end3
109 define void @test3(i32 %a, i32 %b) {
111 %cmp = icmp sle i32 %a, %b
112 br i1 %cmp, label %if.then, label %if.end3
115 %cmp1 = icmp sgt i32 %a, %b
116 br i1 %cmp1, label %if.then2, label %if.end
119 call void @side_effect(i32 0)
131 ; If A >=s B is false then A <=s B is implied true.
132 ; CHECK-LABEL: @test_sge_sle
133 ; CHECK: call void @is(i1 true)
134 ; CHECK-NOT: call void @is(i1 false)
135 define void @test_sge_sle(i32 %a, i32 %b) {
136 %cmp1 = icmp sge i32 %a, %b
137 br i1 %cmp1, label %untaken, label %taken
140 %cmp2 = icmp sle i32 %a, %b
141 br i1 %cmp2, label %istrue, label %isfalse
144 call void @is(i1 true)
148 call void @is(i1 false)
155 ; If A <=s B is false then A <=s B is implied false.
156 ; CHECK-LABEL: @test_sle_sle
157 ; CHECK-NOT: call void @is(i1 true)
158 ; CHECK: call void @is(i1 false)
159 define void @test_sle_sle(i32 %a, i32 %b) {
160 %cmp1 = icmp sle i32 %a, %b
161 br i1 %cmp1, label %untaken, label %taken
164 %cmp2 = icmp sle i32 %a, %b
165 br i1 %cmp2, label %istrue, label %isfalse
168 call void @is(i1 true)
172 call void @is(i1 false)