1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
3 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
5 define i1 @test_eq(i1 %cond) {
6 ; CHECK-LABEL: @test_eq(
8 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
10 ; CHECK-NEXT: br label [[MERGE:%.*]]
12 ; CHECK-NEXT: br label [[MERGE]]
14 ; CHECK-NEXT: br label [[EXIT:%.*]]
16 ; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[COND]], true
17 ; CHECK-NEXT: ret i1 [[TMP0]]
20 br i1 %cond, label %if.true, label %if.false
29 %phi = phi i32 [123, %if.true], [456, %if.false]
33 %compare = icmp eq i32 %phi, 456
37 define i1 @test_slt(i1 %cond) {
38 ; CHECK-LABEL: @test_slt(
40 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
42 ; CHECK-NEXT: br label [[MERGE:%.*]]
44 ; CHECK-NEXT: br label [[MERGE]]
46 ; CHECK-NEXT: br label [[EXIT:%.*]]
48 ; CHECK-NEXT: ret i1 [[COND]]
51 br i1 %cond, label %if.true, label %if.false
60 %phi = phi i32 [123, %if.true], [456, %if.false]
64 %compare = icmp slt i32 %phi, 456
68 define i1 @test_sle(i1 %cond) {
69 ; CHECK-LABEL: @test_sle(
71 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
73 ; CHECK-NEXT: br label [[MERGE:%.*]]
75 ; CHECK-NEXT: br label [[MERGE]]
77 ; CHECK-NEXT: br label [[EXIT:%.*]]
79 ; CHECK-NEXT: ret i1 true
82 br i1 %cond, label %if.true, label %if.false
91 %phi = phi i32 [123, %if.true], [456, %if.false]
95 %compare = icmp sle i32 %phi, 456
99 define i1 @test_ne(i1 %cond) {
100 ; CHECK-LABEL: @test_ne(
102 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
104 ; CHECK-NEXT: br label [[MERGE:%.*]]
106 ; CHECK-NEXT: br label [[MERGE]]
108 ; CHECK-NEXT: br label [[EXIT:%.*]]
110 ; CHECK-NEXT: ret i1 [[COND]]
113 br i1 %cond, label %if.true, label %if.false
122 %phi = phi i32 [123, %if.true], [456, %if.false]
126 %compare = icmp ne i32 %phi, 456
130 define i1 @test_ne_undef(i1 %cond) {
131 ; CHECK-LABEL: @test_ne_undef(
133 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
135 ; CHECK-NEXT: br label [[MERGE:%.*]]
137 ; CHECK-NEXT: br label [[MERGE]]
139 ; CHECK-NEXT: br label [[EXIT:%.*]]
141 ; CHECK-NEXT: ret i1 false
144 br i1 %cond, label %if.true, label %if.false
153 %phi = phi i32 [undef, %if.true], [456, %if.false]
157 %compare = icmp ne i32 %phi, 456
161 define <2 x i1> @test_ne_int_vector(i1 %cond) {
162 ; CHECK-LABEL: @test_ne_int_vector(
164 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
166 ; CHECK-NEXT: br label [[MERGE:%.*]]
168 ; CHECK-NEXT: br label [[MERGE]]
170 ; CHECK-NEXT: [[COMPARE:%.*]] = phi <2 x i1> [ <i1 true, i1 false>, [[IF_FALSE]] ], [ <i1 false, i1 true>, [[IF_TRUE]] ]
171 ; CHECK-NEXT: br label [[EXIT:%.*]]
173 ; CHECK-NEXT: ret <2 x i1> [[COMPARE]]
176 br i1 %cond, label %if.true, label %if.false
185 %phi = phi <2 x i32> [<i32 123, i32 123>, %if.true], [<i32 456, i32 456>, %if.false]
189 %compare = icmp ne <2 x i32> %phi, <i32 123, i32 456>
190 ret <2 x i1> %compare
193 ; TODO: We can also constant-fold this comparison for floats.
194 define i1 @test_ne_float(i1 %cond) {
195 ; CHECK-LABEL: @test_ne_float(
197 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
199 ; CHECK-NEXT: br label [[MERGE:%.*]]
201 ; CHECK-NEXT: br label [[MERGE]]
203 ; CHECK-NEXT: [[PHI:%.*]] = phi float [ 1.000000e+00, [[IF_TRUE]] ], [ 1.250000e+00, [[IF_FALSE]] ]
204 ; CHECK-NEXT: br label [[EXIT:%.*]]
206 ; CHECK-NEXT: [[COMPARE:%.*]] = fcmp one float [[PHI]], 1.250000e+00
207 ; CHECK-NEXT: ret i1 [[COMPARE]]
210 br i1 %cond, label %if.true, label %if.false
219 %phi = phi float [1.0, %if.true], [1.25, %if.false]
223 %compare = fcmp one float %phi, 1.25
227 define i1 @test_ne_float_undef(i1 %cond) {
228 ; CHECK-LABEL: @test_ne_float_undef(
230 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
232 ; CHECK-NEXT: br label [[MERGE:%.*]]
234 ; CHECK-NEXT: br label [[MERGE]]
236 ; CHECK-NEXT: br label [[EXIT:%.*]]
238 ; CHECK-NEXT: ret i1 true
241 br i1 %cond, label %if.true, label %if.false
250 %phi = phi float [1.0, %if.true], [undef, %if.false]
254 %compare = fcmp one float %phi, 1.25
258 define <2 x i1> @test_ne_float_vector(i1 %cond) {
259 ; CHECK-LABEL: @test_ne_float_vector(
261 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
263 ; CHECK-NEXT: br label [[MERGE:%.*]]
265 ; CHECK-NEXT: br label [[MERGE]]
267 ; CHECK-NEXT: [[PHI:%.*]] = phi <2 x float> [ <float 1.232500e+02, float 1.232500e+02>, [[IF_TRUE]] ], [ <float 4.562500e+02, float 4.562500e+02>, [[IF_FALSE]] ]
268 ; CHECK-NEXT: br label [[EXIT:%.*]]
270 ; CHECK-NEXT: [[COMPARE:%.*]] = fcmp one <2 x float> [[PHI]], <float 1.232500e+02, float 4.562500e+02>
271 ; CHECK-NEXT: ret <2 x i1> [[COMPARE]]
274 br i1 %cond, label %if.true, label %if.false
283 %phi = phi <2 x float> [<float 123.25, float 123.25>, %if.true], [<float 456.25, float 456.25>, %if.false]
287 %compare = fcmp one <2 x float> %phi, <float 123.25, float 456.25>
288 ret <2 x i1> %compare