1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2 ; RUN: opt -S -passes=instcombine < %s | FileCheck %s
4 define i1 @test1(float %x) {
5 ; CHECK-LABEL: define i1 @test1(
6 ; CHECK-SAME: float [[X:%.*]]) {
8 ; CHECK-NEXT: [[COND:%.*]] = fcmp ueq float [[X]], 0.000000e+00
9 ; CHECK-NEXT: br i1 [[COND]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
11 ; CHECK-NEXT: ret i1 false
13 ; CHECK-NEXT: [[RET:%.*]] = call i1 @llvm.is.fpclass.f32(float [[X]], i32 780)
14 ; CHECK-NEXT: ret i1 [[RET]]
17 %cond = fcmp ueq float %x, 0.000000e+00
18 br i1 %cond, label %if.then, label %if.else
24 %ret = call i1 @llvm.is.fpclass.f32(float %x, i32 783)
28 define i1 @test2(double %x) {
29 ; CHECK-LABEL: define i1 @test2(
30 ; CHECK-SAME: double [[X:%.*]]) {
32 ; CHECK-NEXT: [[CMP:%.*]] = fcmp olt double [[X]], 0x3EB0C6F7A0000000
33 ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
35 ; CHECK-NEXT: ret i1 false
37 ; CHECK-NEXT: ret i1 false
40 %cmp = fcmp olt double %x, 0x3EB0C6F7A0000000
41 br i1 %cmp, label %if.then, label %if.end
45 %cmp.i = fcmp oeq double %x, 0.000000e+00
49 define i1 @test3(float %x) {
50 ; CHECK-LABEL: define i1 @test3(
51 ; CHECK-SAME: float [[X:%.*]]) {
53 ; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt float [[X]], 3.000000e+00
54 ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
56 ; CHECK-NEXT: [[RET:%.*]] = fcmp oeq float [[X]], 0x7FF0000000000000
57 ; CHECK-NEXT: ret i1 [[RET]]
59 ; CHECK-NEXT: ret i1 false
62 %cmp = fcmp ogt float %x, 3.000000e+00
63 br i1 %cmp, label %if.then, label %if.else
65 %abs = call float @llvm.fabs.f32(float %x)
66 %ret = fcmp oeq float %abs, 0x7FF0000000000000
72 define float @test4(float %x) {
73 ; CHECK-LABEL: define float @test4(
74 ; CHECK-SAME: float [[X:%.*]]) {
76 ; CHECK-NEXT: [[CMP:%.*]] = fcmp olt float [[X]], 0x3EB0C6F7A0000000
77 ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
79 ; CHECK-NEXT: ret float 1.000000e+00
81 ; CHECK-NEXT: [[DIV:%.*]] = fdiv float 1.000000e+00, [[X]]
82 ; CHECK-NEXT: ret float [[DIV]]
85 %cmp = fcmp olt float %x, 0x3EB0C6F7A0000000
86 br i1 %cmp, label %if.then, label %if.end
92 %cmp.i = fcmp oeq float %x, 0.000000e+00
93 %div = fdiv float 1.000000e+00, %x
94 %ret = select i1 %cmp.i, float 1.000000e+00, float %div
98 define i1 @test5(double %x, i1 %cond) {
99 ; CHECK-LABEL: define i1 @test5(
100 ; CHECK-SAME: double [[X:%.*]], i1 [[COND:%.*]]) {
102 ; CHECK-NEXT: br i1 [[COND]], label [[IF:%.*]], label [[EXIT:%.*]]
104 ; CHECK-NEXT: [[CMP:%.*]] = fcmp uno double [[X]], 0.000000e+00
105 ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
107 ; CHECK-NEXT: ret i1 false
109 ; CHECK-NEXT: br label [[EXIT]]
111 ; CHECK-NEXT: [[Y:%.*]] = phi double [ -1.000000e+00, [[ENTRY:%.*]] ], [ [[X]], [[IF_END]] ]
112 ; CHECK-NEXT: [[RET:%.*]] = tail call i1 @llvm.is.fpclass.f64(double [[Y]], i32 408)
113 ; CHECK-NEXT: ret i1 [[RET]]
116 br i1 %cond, label %if, label %exit
118 %cmp = fcmp uno double %x, 0.000000e+00
119 br i1 %cmp, label %if.then, label %if.end
125 %y = phi double [ -1.000000e+00, %entry ], [ %x, %if.end ]
126 %ret = tail call i1 @llvm.is.fpclass.f64(double %y, i32 411)
130 define i1 @test6(double %x) {
131 ; CHECK-LABEL: define i1 @test6(
132 ; CHECK-SAME: double [[X:%.*]]) {
134 ; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt double [[X]], 0.000000e+00
135 ; CHECK-NEXT: br i1 [[CMP]], label [[LAND_RHS:%.*]], label [[LAND_END:%.*]]
137 ; CHECK-NEXT: [[CMP_I:%.*]] = fcmp oeq double [[X]], 0x7FF0000000000000
138 ; CHECK-NEXT: br label [[LAND_END]]
140 ; CHECK-NEXT: [[RET:%.*]] = phi i1 [ false, [[ENTRY:%.*]] ], [ [[CMP_I]], [[LAND_RHS]] ]
141 ; CHECK-NEXT: ret i1 [[RET]]
144 %cmp = fcmp ogt double %x, 0.000000e+00
145 br i1 %cmp, label %land.rhs, label %land.end
148 %abs = tail call double @llvm.fabs.f64(double %x)
149 %and.i = bitcast double %abs to i64
150 %cmp.i = icmp eq i64 %and.i, 9218868437227405312
154 %ret = phi i1 [ false, %entry ], [ %cmp.i, %land.rhs ]
158 define i1 @test7(float %x) {
159 ; CHECK-LABEL: define i1 @test7(
160 ; CHECK-SAME: float [[X:%.*]]) {
161 ; CHECK-NEXT: [[COND:%.*]] = call i1 @llvm.is.fpclass.f32(float [[X]], i32 345)
162 ; CHECK-NEXT: br i1 [[COND]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
164 ; CHECK-NEXT: [[RET1:%.*]] = call i1 @llvm.is.fpclass.f32(float [[X]], i32 328)
165 ; CHECK-NEXT: ret i1 [[RET1]]
167 ; CHECK-NEXT: [[RET2:%.*]] = call i1 @llvm.is.fpclass.f32(float [[X]], i32 128)
168 ; CHECK-NEXT: ret i1 [[RET2]]
170 %cond = call i1 @llvm.is.fpclass.f32(float %x, i32 345)
171 br i1 %cond, label %if.then, label %if.else
173 %ret1 = call i1 @llvm.is.fpclass.f32(float %x, i32 456)
176 %ret2 = call i1 @llvm.is.fpclass.f32(float %x, i32 456)
180 ; TODO: These two is.fpclass can be simplified.
181 define i1 @test8(float %x) {
182 ; CHECK-LABEL: define i1 @test8(
183 ; CHECK-SAME: float [[X:%.*]]) {
184 ; CHECK-NEXT: [[ABS:%.*]] = call float @llvm.fabs.f32(float [[X]])
185 ; CHECK-NEXT: [[COND:%.*]] = fcmp oeq float [[ABS]], 0x7FF0000000000000
186 ; CHECK-NEXT: br i1 [[COND]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
188 ; CHECK-NEXT: ret i1 true
190 ; CHECK-NEXT: [[RET2:%.*]] = call i1 @llvm.is.fpclass.f32(float [[X]], i32 59)
191 ; CHECK-NEXT: ret i1 [[RET2]]
193 %abs = call float @llvm.fabs.f32(float %x)
194 %cond = fcmp oeq float %abs, 0x7FF0000000000000
195 br i1 %cond, label %if.then, label %if.else
197 %ret1 = call i1 @llvm.is.fpclass.f32(float %x, i32 575)
200 %ret2 = call i1 @llvm.is.fpclass.f32(float %x, i32 575)
204 define i1 @test9(float %x) {
205 ; CHECK-LABEL: define i1 @test9(
206 ; CHECK-SAME: float [[X:%.*]]) {
207 ; CHECK-NEXT: [[COND:%.*]] = fcmp olt float [[X]], -1.000000e+00
208 ; CHECK-NEXT: br i1 [[COND]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
210 ; CHECK-NEXT: ret i1 false
212 ; CHECK-NEXT: ret i1 false
214 %cond = fcmp olt float %x, -1.0
215 br i1 %cond, label %if.then, label %if.else
217 %ret1 = fcmp oeq float %x, 0x7FF0000000000000
223 define i1 @test10(float %x) {
224 ; CHECK-LABEL: define i1 @test10(
225 ; CHECK-SAME: float [[X:%.*]]) {
226 ; CHECK-NEXT: [[COND:%.*]] = fcmp olt float [[X]], -1.000000e+00
227 ; CHECK-NEXT: br i1 [[COND]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
229 ; CHECK-NEXT: ret i1 false
231 ; CHECK-NEXT: ret i1 false
233 %cond = fcmp olt float %x, -1.0
235 br i1 %cond, label %if.then, label %if.else
237 %ret1 = fcmp oeq float %neg, 0xFFF0000000000000
243 ; TODO: handle and/or conditions
244 define i1 @test11_and(float %x, i1 %cond2) {
245 ; CHECK-LABEL: define i1 @test11_and(
246 ; CHECK-SAME: float [[X:%.*]], i1 [[COND2:%.*]]) {
247 ; CHECK-NEXT: [[COND:%.*]] = fcmp olt float [[X]], -1.000000e+00
248 ; CHECK-NEXT: [[AND:%.*]] = and i1 [[COND]], [[COND2]]
249 ; CHECK-NEXT: br i1 [[AND]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
251 ; CHECK-NEXT: [[RET1:%.*]] = fcmp oeq float [[X]], 0x7FF0000000000000
252 ; CHECK-NEXT: ret i1 [[RET1]]
254 ; CHECK-NEXT: ret i1 false
256 %cond = fcmp olt float %x, -1.0
258 %and = and i1 %cond, %cond2
259 br i1 %and, label %if.then, label %if.else
261 %ret1 = fcmp oeq float %neg, 0xFFF0000000000000
267 ; TODO: handle and/or conditions
268 define i1 @test12_or(float %x, i1 %cond2) {
269 ; CHECK-LABEL: define i1 @test12_or(
270 ; CHECK-SAME: float [[X:%.*]], i1 [[COND2:%.*]]) {
272 ; CHECK-NEXT: [[COND:%.*]] = fcmp ueq float [[X]], 0.000000e+00
273 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[COND]], [[COND2]]
274 ; CHECK-NEXT: br i1 [[OR]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
276 ; CHECK-NEXT: ret i1 false
278 ; CHECK-NEXT: [[RET:%.*]] = call i1 @llvm.is.fpclass.f32(float [[X]], i32 783)
279 ; CHECK-NEXT: ret i1 [[RET]]
282 %cond = fcmp ueq float %x, 0.000000e+00
283 %or = or i1 %cond, %cond2
284 br i1 %or, label %if.then, label %if.else
290 %ret = call i1 @llvm.is.fpclass.f32(float %x, i32 783)
294 define i1 @test1_no_dominating(float %x, i1 %c) {
295 ; CHECK-LABEL: define i1 @test1_no_dominating(
296 ; CHECK-SAME: float [[X:%.*]], i1 [[C:%.*]]) {
297 ; CHECK-NEXT: entry0:
298 ; CHECK-NEXT: br i1 [[C]], label [[ENTRY:%.*]], label [[IF_ELSE:%.*]]
300 ; CHECK-NEXT: [[COND:%.*]] = fcmp ueq float [[X]], 0.000000e+00
301 ; CHECK-NEXT: br i1 [[COND]], label [[IF_THEN:%.*]], label [[IF_ELSE]]
303 ; CHECK-NEXT: ret i1 false
305 ; CHECK-NEXT: [[RET:%.*]] = call i1 @llvm.is.fpclass.f32(float [[X]], i32 783)
306 ; CHECK-NEXT: ret i1 [[RET]]
309 br i1 %c, label %entry, label %if.else
312 %cond = fcmp ueq float %x, 0.000000e+00
313 br i1 %cond, label %if.then, label %if.else
319 %ret = call i1 @llvm.is.fpclass.f32(float %x, i32 783)
323 define float @test_signbit_check(float %x, i1 %cond) {
324 ; CHECK-LABEL: define float @test_signbit_check(
325 ; CHECK-SAME: float [[X:%.*]], i1 [[COND:%.*]]) {
326 ; CHECK-NEXT: [[I32:%.*]] = bitcast float [[X]] to i32
327 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[I32]], 0
328 ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN1:%.*]], label [[IF_ELSE:%.*]]
330 ; CHECK-NEXT: [[FNEG:%.*]] = fneg float [[X]]
331 ; CHECK-NEXT: br label [[IF_END:%.*]]
333 ; CHECK-NEXT: br i1 [[COND]], label [[IF_THEN2:%.*]], label [[IF_END]]
335 ; CHECK-NEXT: br label [[IF_END]]
337 ; CHECK-NEXT: [[VALUE:%.*]] = phi float [ [[FNEG]], [[IF_THEN1]] ], [ [[X]], [[IF_THEN2]] ], [ [[X]], [[IF_ELSE]] ]
338 ; CHECK-NEXT: ret float [[VALUE]]
340 %i32 = bitcast float %x to i32
341 %cmp = icmp slt i32 %i32, 0
342 br i1 %cmp, label %if.then1, label %if.else
345 %fneg = fneg float %x
349 br i1 %cond, label %if.then2, label %if.end
355 %value = phi float [ %fneg, %if.then1 ], [ %x, %if.then2 ], [ %x, %if.else ]
356 %ret = call float @llvm.fabs.f32(float %value)
360 define float @test_signbit_check_fail(float %x, i1 %cond) {
361 ; CHECK-LABEL: define float @test_signbit_check_fail(
362 ; CHECK-SAME: float [[X:%.*]], i1 [[COND:%.*]]) {
363 ; CHECK-NEXT: [[I32:%.*]] = bitcast float [[X]] to i32
364 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[I32]], 0
365 ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN1:%.*]], label [[IF_ELSE:%.*]]
367 ; CHECK-NEXT: [[FNEG:%.*]] = fneg float [[X]]
368 ; CHECK-NEXT: br label [[IF_END:%.*]]
370 ; CHECK-NEXT: br i1 [[COND]], label [[IF_THEN2:%.*]], label [[IF_END]]
372 ; CHECK-NEXT: [[FNEG2:%.*]] = fneg float [[X]]
373 ; CHECK-NEXT: br label [[IF_END]]
375 ; CHECK-NEXT: [[VALUE:%.*]] = phi float [ [[FNEG]], [[IF_THEN1]] ], [ [[FNEG2]], [[IF_THEN2]] ], [ [[X]], [[IF_ELSE]] ]
376 ; CHECK-NEXT: [[RET:%.*]] = call float @llvm.fabs.f32(float [[VALUE]])
377 ; CHECK-NEXT: ret float [[RET]]
379 %i32 = bitcast float %x to i32
380 %cmp = icmp slt i32 %i32, 0
381 br i1 %cmp, label %if.then1, label %if.else
384 %fneg = fneg float %x
388 br i1 %cond, label %if.then2, label %if.end
391 %fneg2 = fneg float %x
395 %value = phi float [ %fneg, %if.then1 ], [ %fneg2, %if.then2 ], [ %x, %if.else ]
396 %ret = call float @llvm.fabs.f32(float %value)
400 define <2 x float> @test_signbit_check_wrong_type(<2 x float> %x, i1 %cond) {
401 ; CHECK-LABEL: define <2 x float> @test_signbit_check_wrong_type(
402 ; CHECK-SAME: <2 x float> [[X:%.*]], i1 [[COND:%.*]]) {
403 ; CHECK-NEXT: [[I32:%.*]] = bitcast <2 x float> [[X]] to i64
404 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i64 [[I32]], 0
405 ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN1:%.*]], label [[IF_ELSE:%.*]]
407 ; CHECK-NEXT: [[FNEG:%.*]] = fneg <2 x float> [[X]]
408 ; CHECK-NEXT: br label [[IF_END:%.*]]
410 ; CHECK-NEXT: br i1 [[COND]], label [[IF_THEN2:%.*]], label [[IF_END]]
412 ; CHECK-NEXT: br label [[IF_END]]
414 ; CHECK-NEXT: [[VALUE:%.*]] = phi <2 x float> [ [[FNEG]], [[IF_THEN1]] ], [ [[X]], [[IF_THEN2]] ], [ [[X]], [[IF_ELSE]] ]
415 ; CHECK-NEXT: [[RET:%.*]] = call <2 x float> @llvm.fabs.v2f32(<2 x float> [[VALUE]])
416 ; CHECK-NEXT: ret <2 x float> [[RET]]
418 %i32 = bitcast <2 x float> %x to i64
419 %cmp = icmp slt i64 %i32, 0
420 br i1 %cmp, label %if.then1, label %if.else
423 %fneg = fneg <2 x float> %x
427 br i1 %cond, label %if.then2, label %if.end
433 %value = phi <2 x float> [ %fneg, %if.then1 ], [ %x, %if.then2 ], [ %x, %if.else ]
434 %ret = call <2 x float> @llvm.fabs.v2f32(<2 x float> %value)