1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 define i1 @test_eq(i1 %cond) {
5 ; CHECK-LABEL: @test_eq(
7 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
9 ; CHECK-NEXT: br label [[MERGE:%.*]]
11 ; CHECK-NEXT: br label [[MERGE]]
13 ; CHECK-NEXT: br label [[EXIT:%.*]]
15 ; CHECK-NEXT: [[COMPARE:%.*]] = xor i1 [[COND]], true
16 ; CHECK-NEXT: ret i1 [[COMPARE]]
19 br i1 %cond, label %if.true, label %if.false
28 %phi = phi i32 [123, %if.true], [456, %if.false]
32 %compare = icmp eq i32 %phi, 456
36 define i1 @test_slt(i1 %cond) {
37 ; CHECK-LABEL: @test_slt(
39 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
41 ; CHECK-NEXT: br label [[MERGE:%.*]]
43 ; CHECK-NEXT: br label [[MERGE]]
45 ; CHECK-NEXT: br label [[EXIT:%.*]]
47 ; CHECK-NEXT: ret i1 [[COND]]
50 br i1 %cond, label %if.true, label %if.false
59 %phi = phi i32 [123, %if.true], [456, %if.false]
63 %compare = icmp slt i32 %phi, 456
67 define i1 @test_sle(i1 %cond) {
68 ; CHECK-LABEL: @test_sle(
70 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
72 ; CHECK-NEXT: br label [[MERGE:%.*]]
74 ; CHECK-NEXT: br label [[MERGE]]
76 ; CHECK-NEXT: br label [[EXIT:%.*]]
78 ; CHECK-NEXT: ret i1 true
81 br i1 %cond, label %if.true, label %if.false
90 %phi = phi i32 [123, %if.true], [456, %if.false]
94 %compare = icmp sle i32 %phi, 456
98 define i1 @test_ne(i1 %cond) {
99 ; CHECK-LABEL: @test_ne(
101 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
103 ; CHECK-NEXT: br label [[MERGE:%.*]]
105 ; CHECK-NEXT: br label [[MERGE]]
107 ; CHECK-NEXT: br label [[EXIT:%.*]]
109 ; CHECK-NEXT: ret i1 [[COND]]
112 br i1 %cond, label %if.true, label %if.false
121 %phi = phi i32 [123, %if.true], [456, %if.false]
125 %compare = icmp ne i32 %phi, 456
129 define i1 @test_ne_undef(i1 %cond) {
130 ; CHECK-LABEL: @test_ne_undef(
132 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
134 ; CHECK-NEXT: br label [[MERGE:%.*]]
136 ; CHECK-NEXT: br label [[MERGE]]
138 ; CHECK-NEXT: br label [[EXIT:%.*]]
140 ; CHECK-NEXT: ret i1 false
143 br i1 %cond, label %if.true, label %if.false
152 %phi = phi i32 [undef, %if.true], [456, %if.false]
156 %compare = icmp ne i32 %phi, 456
160 define <2 x i1> @test_ne_int_vector(i1 %cond) {
161 ; CHECK-LABEL: @test_ne_int_vector(
163 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
165 ; CHECK-NEXT: br label [[MERGE:%.*]]
167 ; CHECK-NEXT: br label [[MERGE]]
169 ; CHECK-NEXT: [[COMPARE:%.*]] = phi <2 x i1> [ <i1 false, i1 true>, [[IF_TRUE]] ], [ <i1 true, i1 false>, [[IF_FALSE]] ]
170 ; CHECK-NEXT: br label [[EXIT:%.*]]
172 ; CHECK-NEXT: ret <2 x i1> [[COMPARE]]
175 br i1 %cond, label %if.true, label %if.false
184 %phi = phi <2 x i32> [<i32 123, i32 123>, %if.true], [<i32 456, i32 456>, %if.false]
188 %compare = icmp ne <2 x i32> %phi, <i32 123, i32 456>
189 ret <2 x i1> %compare
192 ; TODO: We can also constant-fold this comparison for floats.
193 define i1 @test_ne_float(i1 %cond) {
194 ; CHECK-LABEL: @test_ne_float(
196 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
198 ; CHECK-NEXT: br label [[MERGE:%.*]]
200 ; CHECK-NEXT: br label [[MERGE]]
202 ; CHECK-NEXT: br label [[EXIT:%.*]]
204 ; CHECK-NEXT: ret i1 [[COND]]
207 br i1 %cond, label %if.true, label %if.false
216 %phi = phi float [1.0, %if.true], [1.25, %if.false]
220 %compare = fcmp one float %phi, 1.25
224 define i1 @test_ne_float_undef(i1 %cond) {
225 ; CHECK-LABEL: @test_ne_float_undef(
227 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
229 ; CHECK-NEXT: br label [[MERGE:%.*]]
231 ; CHECK-NEXT: br label [[MERGE]]
233 ; CHECK-NEXT: br label [[EXIT:%.*]]
235 ; CHECK-NEXT: ret i1 true
238 br i1 %cond, label %if.true, label %if.false
247 %phi = phi float [1.0, %if.true], [undef, %if.false]
251 %compare = fcmp one float %phi, 1.25
255 define <2 x i1> @test_ne_float_vector(i1 %cond) {
256 ; CHECK-LABEL: @test_ne_float_vector(
258 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
260 ; CHECK-NEXT: br label [[MERGE:%.*]]
262 ; CHECK-NEXT: br label [[MERGE]]
264 ; CHECK-NEXT: [[PHI:%.*]] = phi <2 x i1> [ <i1 false, i1 true>, [[IF_TRUE]] ], [ <i1 true, i1 false>, [[IF_FALSE]] ]
265 ; CHECK-NEXT: br label [[EXIT:%.*]]
267 ; CHECK-NEXT: ret <2 x i1> [[PHI]]
270 br i1 %cond, label %if.true, label %if.false
279 %phi = phi <2 x float> [<float 123.25, float 123.25>, %if.true], [<float 456.25, float 456.25>, %if.false]
283 %compare = fcmp one <2 x float> %phi, <float 123.25, float 456.25>
284 ret <2 x i1> %compare