1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instsimplify -S | FileCheck %s
6 define i1 @inf0(double %arg) {
8 ; CHECK-NEXT: ret i1 false
10 %tmp = fcmp ogt double %arg, 0x7FF0000000000000
14 define i1 @inf1(double %arg) {
16 ; CHECK-NEXT: ret i1 true
18 %tmp = fcmp ule double %arg, 0x7FF0000000000000
24 define i1 @ninf0(double %arg) {
25 ; CHECK-LABEL: @ninf0(
26 ; CHECK-NEXT: ret i1 false
28 %tmp = fcmp olt double %arg, 0xFFF0000000000000
32 define i1 @ninf1(double %arg) {
33 ; CHECK-LABEL: @ninf1(
34 ; CHECK-NEXT: ret i1 true
36 %tmp = fcmp uge double %arg, 0xFFF0000000000000
42 define i1 @nan0(double %arg) {
44 ; CHECK-NEXT: ret i1 false
46 %tmp = fcmp ord double %arg, 0x7FF00000FFFFFFFF
50 define i1 @nan1(double %arg) {
52 ; CHECK-NEXT: ret i1 false
54 %tmp = fcmp oeq double %arg, 0x7FF00000FFFFFFFF
58 define i1 @nan2(double %arg) {
60 ; CHECK-NEXT: ret i1 false
62 %tmp = fcmp olt double %arg, 0x7FF00000FFFFFFFF
66 define i1 @nan3(double %arg) {
68 ; CHECK-NEXT: ret i1 true
70 %tmp = fcmp uno double %arg, 0x7FF00000FFFFFFFF
74 define i1 @nan4(double %arg) {
76 ; CHECK-NEXT: ret i1 true
78 %tmp = fcmp une double %arg, 0x7FF00000FFFFFFFF
82 define i1 @nan5(double %arg) {
84 ; CHECK-NEXT: ret i1 true
86 %tmp = fcmp ult double %arg, 0x7FF00000FFFFFFFF
92 define i1 @nnan0(double %arg) {
93 ; CHECK-LABEL: @nnan0(
94 ; CHECK-NEXT: ret i1 false
96 %tmp = fcmp ord double %arg, 0xFFF00000FFFFFFFF
100 define i1 @nnan1(double %arg) {
101 ; CHECK-LABEL: @nnan1(
102 ; CHECK-NEXT: ret i1 false
104 %tmp = fcmp oeq double %arg, 0xFFF00000FFFFFFFF
108 define i1 @nnan2(double %arg) {
109 ; CHECK-LABEL: @nnan2(
110 ; CHECK-NEXT: ret i1 false
112 %tmp = fcmp olt double %arg, 0xFFF00000FFFFFFFF
116 define i1 @nnan3(double %arg) {
117 ; CHECK-LABEL: @nnan3(
118 ; CHECK-NEXT: ret i1 true
120 %tmp = fcmp uno double %arg, 0xFFF00000FFFFFFFF
124 define i1 @nnan4(double %arg) {
125 ; CHECK-LABEL: @nnan4(
126 ; CHECK-NEXT: ret i1 true
128 %tmp = fcmp une double %arg, 0xFFF00000FFFFFFFF
132 define i1 @nnan5(double %arg) {
133 ; CHECK-LABEL: @nnan5(
134 ; CHECK-NEXT: ret i1 true
136 %tmp = fcmp ult double %arg, 0xFFF00000FFFFFFFF
142 define i1 @nzero0() {
143 ; CHECK-LABEL: @nzero0(
144 ; CHECK-NEXT: ret i1 true
146 %tmp = fcmp oeq double 0.0, -0.0
150 define i1 @nzero1() {
151 ; CHECK-LABEL: @nzero1(
152 ; CHECK-NEXT: ret i1 false
154 %tmp = fcmp ogt double 0.0, -0.0
158 ; No enlightenment here.
160 define i1 @one_with_self(double %arg) {
161 ; CHECK-LABEL: @one_with_self(
162 ; CHECK-NEXT: ret i1 false
164 %tmp = fcmp one double %arg, %arg
168 ; These tests choose arbitrarily between float and double,
169 ; and between uge and olt, to give reasonble coverage
170 ; without combinatorial explosion.
172 declare half @llvm.fabs.f16(half)
173 declare float @llvm.fabs.f32(float)
174 declare double @llvm.fabs.f64(double)
175 declare <2 x float> @llvm.fabs.v2f32(<2 x float>)
176 declare <3 x float> @llvm.fabs.v3f32(<3 x float>)
177 declare <2 x double> @llvm.fabs.v2f64(<2 x double>)
178 declare float @llvm.sqrt.f32(float)
179 declare double @llvm.powi.f64(double,i32)
180 declare float @llvm.exp.f32(float)
181 declare float @llvm.minnum.f32(float, float)
182 declare <2 x float> @llvm.minnum.v2f32(<2 x float>, <2 x float>)
183 declare float @llvm.maxnum.f32(float, float)
184 declare <2 x float> @llvm.maxnum.v2f32(<2 x float>, <2 x float>)
185 declare float @llvm.maximum.f32(float, float)
186 declare double @llvm.exp2.f64(double)
187 declare float @llvm.fma.f32(float,float,float)
189 declare void @expect_equal(i1,i1)
191 define i1 @orderedLessZeroTree(float,float,float,float) {
192 ; CHECK-LABEL: @orderedLessZeroTree(
193 ; CHECK-NEXT: ret i1 true
195 %square = fmul float %0, %0
196 %abs = call float @llvm.fabs.f32(float %1)
197 %sqrt = call float @llvm.sqrt.f32(float %2)
198 %fma = call float @llvm.fma.f32(float %3, float %3, float %sqrt)
199 %div = fdiv float %square, %abs
200 %rem = frem float %sqrt, %fma
201 %add = fadd float %div, %rem
202 %uge = fcmp uge float %add, 0.000000e+00
206 define i1 @orderedLessZeroExpExt(float) {
207 ; CHECK-LABEL: @orderedLessZeroExpExt(
208 ; CHECK-NEXT: ret i1 true
210 %a = call float @llvm.exp.f32(float %0)
211 %b = fpext float %a to double
212 %uge = fcmp uge double %b, 0.000000e+00
216 define i1 @orderedLessZeroExp2Trunc(double) {
217 ; CHECK-LABEL: @orderedLessZeroExp2Trunc(
218 ; CHECK-NEXT: ret i1 false
220 %a = call double @llvm.exp2.f64(double %0)
221 %b = fptrunc double %a to float
222 %olt = fcmp olt float %b, 0.000000e+00
226 define i1 @orderedLessZeroPowi(double,double) {
227 ; CHECK-LABEL: @orderedLessZeroPowi(
228 ; CHECK-NEXT: ret i1 false
230 ; Even constant exponent
231 %a = call double @llvm.powi.f64(double %0, i32 2)
232 %square = fmul double %1, %1
233 ; Odd constant exponent with provably non-negative base
234 %b = call double @llvm.powi.f64(double %square, i32 3)
235 %c = fadd double %a, %b
236 %olt = fcmp olt double %b, 0.000000e+00
240 define i1 @UIToFP_is_nan_or_positive_or_zero(i32 %x) {
241 ; CHECK-LABEL: @UIToFP_is_nan_or_positive_or_zero(
242 ; CHECK-NEXT: ret i1 true
244 %a = uitofp i32 %x to float
245 %r = fcmp uge float %a, 0.000000e+00
249 define <2 x i1> @UIToFP_is_nan_or_positive_or_zero_vec(<2 x i32> %x) {
250 ; CHECK-LABEL: @UIToFP_is_nan_or_positive_or_zero_vec(
251 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
253 %a = uitofp <2 x i32> %x to <2 x float>
254 %r = fcmp uge <2 x float> %a, zeroinitializer
258 define i1 @UIToFP_is_positive_or_zero(i32 %x) {
259 ; CHECK-LABEL: @UIToFP_is_positive_or_zero(
260 ; CHECK-NEXT: ret i1 true
262 %a = uitofp i32 %x to float
263 %r = fcmp oge float %a, 0.000000e+00
267 define <2 x i1> @UIToFP_is_positive_or_zero_vec(<2 x i32> %x) {
268 ; CHECK-LABEL: @UIToFP_is_positive_or_zero_vec(
269 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
271 %a = uitofp <2 x i32> %x to <2 x float>
272 %r = fcmp oge <2 x float> %a, zeroinitializer
276 define i1 @UIToFP_nnan_is_positive_or_zero(i32 %x) {
277 ; CHECK-LABEL: @UIToFP_nnan_is_positive_or_zero(
278 ; CHECK-NEXT: ret i1 true
280 %a = uitofp i32 %x to float
281 %r = fcmp nnan oge float %a, 0.000000e+00
285 define <2 x i1> @UIToFP_nnan_is_positive_or_zero_vec(<2 x i32> %x) {
286 ; CHECK-LABEL: @UIToFP_nnan_is_positive_or_zero_vec(
287 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
289 %a = uitofp <2 x i32> %x to <2 x float>
290 %r = fcmp nnan oge <2 x float> %a, zeroinitializer
294 define i1 @UIToFP_is_not_negative(i32 %x) {
295 ; CHECK-LABEL: @UIToFP_is_not_negative(
296 ; CHECK-NEXT: ret i1 false
298 %a = uitofp i32 %x to float
299 %r = fcmp olt float %a, 0.000000e+00
303 define <2 x i1> @UIToFP_is_not_negative_vec(<2 x i32> %x) {
304 ; CHECK-LABEL: @UIToFP_is_not_negative_vec(
305 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
307 %a = uitofp <2 x i32> %x to <2 x float>
308 %r = fcmp olt <2 x float> %a, zeroinitializer
312 ; No FMF are required for this transform.
314 define i1 @UIToFP_is_not_negative_or_nan(i32 %x) {
315 ; CHECK-LABEL: @UIToFP_is_not_negative_or_nan(
316 ; CHECK-NEXT: ret i1 false
318 %a = uitofp i32 %x to float
319 %r = fcmp ult float %a, 0.000000e+00
323 define <2 x i1> @UIToFP_is_not_negative_or_nan_vec(<2 x i32> %x) {
324 ; CHECK-LABEL: @UIToFP_is_not_negative_or_nan_vec(
325 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
327 %a = uitofp <2 x i32> %x to <2 x float>
328 %r = fcmp ult <2 x float> %a, zeroinitializer
332 define i1 @UIToFP_nnan_is_not_negative(i32 %x) {
333 ; CHECK-LABEL: @UIToFP_nnan_is_not_negative(
334 ; CHECK-NEXT: ret i1 false
336 %a = uitofp i32 %x to float
337 %r = fcmp nnan ult float %a, 0.000000e+00
341 define <2 x i1> @UIToFP_nnan_is_not_negative_vec(<2 x i32> %x) {
342 ; CHECK-LABEL: @UIToFP_nnan_is_not_negative_vec(
343 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
345 %a = uitofp <2 x i32> %x to <2 x float>
346 %r = fcmp nnan ult <2 x float> %a, zeroinitializer
350 define i1 @fabs_is_nan_or_positive_or_zero(double %x) {
351 ; CHECK-LABEL: @fabs_is_nan_or_positive_or_zero(
352 ; CHECK-NEXT: ret i1 true
354 %fabs = tail call double @llvm.fabs.f64(double %x)
355 %cmp = fcmp uge double %fabs, 0.0
359 define <2 x i1> @fabs_is_nan_or_positive_or_zero_vec(<2 x double> %x) {
360 ; CHECK-LABEL: @fabs_is_nan_or_positive_or_zero_vec(
361 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
363 %fabs = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
364 %cmp = fcmp uge <2 x double> %fabs, zeroinitializer
368 define i1 @fabs_nnan_is_positive_or_zero(double %x) {
369 ; CHECK-LABEL: @fabs_nnan_is_positive_or_zero(
370 ; CHECK-NEXT: ret i1 true
372 %fabs = tail call nnan double @llvm.fabs.f64(double %x)
373 %cmp = fcmp oge double %fabs, 0.0
377 define <2 x i1> @fabs_nnan_is_positive_or_zero_vec(<2 x double> %x) {
378 ; CHECK-LABEL: @fabs_nnan_is_positive_or_zero_vec(
379 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
381 %fabs = tail call nnan <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
382 %cmp = fcmp oge <2 x double> %fabs, zeroinitializer
386 define i1 @fabs_fcmp-nnan_is_positive_or_zero(double %x) {
387 ; CHECK-LABEL: @fabs_fcmp-nnan_is_positive_or_zero(
388 ; CHECK-NEXT: ret i1 true
390 %fabs = tail call double @llvm.fabs.f64(double %x)
391 %cmp = fcmp nnan oge double %fabs, 0.0
395 define <2 x i1> @fabs_fcmp-nnan_is_positive_or_zero_vec(<2 x double> %x) {
396 ; CHECK-LABEL: @fabs_fcmp-nnan_is_positive_or_zero_vec(
397 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
399 %fabs = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
400 %cmp = fcmp nnan oge <2 x double> %fabs, zeroinitializer
404 define i1 @fabs_is_not_negative(double %x) {
405 ; CHECK-LABEL: @fabs_is_not_negative(
406 ; CHECK-NEXT: ret i1 false
408 %fabs = tail call double @llvm.fabs.f64(double %x)
409 %cmp = fcmp olt double %fabs, 0.0
413 define <2 x i1> @fabs_is_not_negative_vec(<2 x double> %x) {
414 ; CHECK-LABEL: @fabs_is_not_negative_vec(
415 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
417 %fabs = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
418 %cmp = fcmp olt <2 x double> %fabs, zeroinitializer
422 define i1 @fabs_nnan_is_not_negative(double %x) {
423 ; CHECK-LABEL: @fabs_nnan_is_not_negative(
424 ; CHECK-NEXT: ret i1 false
426 %fabs = tail call nnan double @llvm.fabs.f64(double %x)
427 %cmp = fcmp ult double %fabs, 0.0
431 define <2 x i1> @fabs_nnan_is_not_negative_vec(<2 x double> %x) {
432 ; CHECK-LABEL: @fabs_nnan_is_not_negative_vec(
433 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
435 %fabs = tail call nnan <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
436 %cmp = fcmp ult <2 x double> %fabs, zeroinitializer
440 define i1 @fabs_fcmp-nnan_is_not_negative(double %x) {
441 ; CHECK-LABEL: @fabs_fcmp-nnan_is_not_negative(
442 ; CHECK-NEXT: ret i1 false
444 %fabs = tail call double @llvm.fabs.f64(double %x)
445 %cmp = fcmp nnan ult double %fabs, 0.0
449 define <2 x i1> @fabs_fcmp-nnan_is_not_negative_vec(<2 x double> %x) {
450 ; CHECK-LABEL: @fabs_fcmp-nnan_is_not_negative_vec(
451 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
453 %fabs = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
454 %cmp = fcmp nnan ult <2 x double> %fabs, zeroinitializer
458 define <2 x i1> @fabs_is_not_negative_negzero(<2 x float> %V) {
459 ; CHECK-LABEL: @fabs_is_not_negative_negzero(
460 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
462 %abs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %V)
463 %cmp = fcmp olt <2 x float> %abs, <float -0.0, float -0.0>
467 define <2 x i1> @fabs_is_not_negative_poszero(<2 x float> %V) {
468 ; CHECK-LABEL: @fabs_is_not_negative_poszero(
469 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
471 %abs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %V)
472 %cmp = fcmp olt <2 x float> %abs, <float 0.0, float 0.0>
476 define <2 x i1> @fabs_is_not_negative_anyzero(<2 x float> %V) {
477 ; CHECK-LABEL: @fabs_is_not_negative_anyzero(
478 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
480 %abs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %V)
481 %cmp = fcmp olt <2 x float> %abs, <float 0.0, float -0.0>
485 define <3 x i1> @fabs_is_not_negative_negzero_undef(<3 x float> %V) {
486 ; CHECK-LABEL: @fabs_is_not_negative_negzero_undef(
487 ; CHECK-NEXT: ret <3 x i1> zeroinitializer
489 %abs = call <3 x float> @llvm.fabs.v3f32(<3 x float> %V)
490 %cmp = fcmp olt <3 x float> %abs, <float -0.0, float -0.0, float undef>
494 define <3 x i1> @fabs_is_not_negative_poszero_undef(<3 x float> %V) {
495 ; CHECK-LABEL: @fabs_is_not_negative_poszero_undef(
496 ; CHECK-NEXT: ret <3 x i1> zeroinitializer
498 %abs = call <3 x float> @llvm.fabs.v3f32(<3 x float> %V)
499 %cmp = fcmp olt <3 x float> %abs, <float 0.0, float 0.0, float undef>
503 define <3 x i1> @fabs_is_not_negative_anyzero_undef(<3 x float> %V) {
504 ; CHECK-LABEL: @fabs_is_not_negative_anyzero_undef(
505 ; CHECK-NEXT: ret <3 x i1> zeroinitializer
507 %abs = call <3 x float> @llvm.fabs.v3f32(<3 x float> %V)
508 %cmp = fcmp olt <3 x float> %abs, <float 0.0, float -0.0, float undef>
512 define i1 @orderedLessZeroSelect(float, float) {
513 ; CHECK-LABEL: @orderedLessZeroSelect(
514 ; CHECK-NEXT: ret i1 true
516 %a = call float @llvm.exp.f32(float %0)
517 %b = call float @llvm.fabs.f32(float %1)
518 %c = fcmp olt float %0, %1
519 %d = select i1 %c, float %a, float %b
520 %e = fadd float %d, 1.0
521 %uge = fcmp uge float %e, 0.000000e+00
525 define i1 @orderedLessZeroMinNum(float, float) {
526 ; CHECK-LABEL: @orderedLessZeroMinNum(
527 ; CHECK-NEXT: ret i1 true
529 %a = call float @llvm.exp.f32(float %0)
530 %b = call float @llvm.fabs.f32(float %1)
531 %c = call float @llvm.minnum.f32(float %a, float %b)
532 %uge = fcmp uge float %c, 0.000000e+00
536 ; PR37776: https://bugs.llvm.org/show_bug.cgi?id=37776
537 ; exp() may return nan, leaving %1 as the unknown result, so we can't simplify.
539 define i1 @orderedLessZeroMaxNum(float, float) {
540 ; CHECK-LABEL: @orderedLessZeroMaxNum(
541 ; CHECK-NEXT: [[A:%.*]] = call float @llvm.exp.f32(float [[TMP0:%.*]])
542 ; CHECK-NEXT: [[B:%.*]] = call float @llvm.maxnum.f32(float [[A]], float [[TMP1:%.*]])
543 ; CHECK-NEXT: [[UGE:%.*]] = fcmp uge float [[B]], 0.000000e+00
544 ; CHECK-NEXT: ret i1 [[UGE]]
546 %a = call float @llvm.exp.f32(float %0)
547 %b = call float @llvm.maxnum.f32(float %a, float %1)
548 %uge = fcmp uge float %b, 0.000000e+00
552 ; But using maximum, we can simplify, since the NaN would be propagated
554 define i1 @orderedLessZeroMaximum(float, float) {
555 ; CHECK-LABEL: @orderedLessZeroMaximum(
556 ; CHECK-NEXT: ret i1 true
558 %a = call float @llvm.exp.f32(float %0)
559 %b = call float @llvm.maximum.f32(float %a, float %1)
560 %uge = fcmp uge float %b, 0.000000e+00
564 define i1 @minnum_non_nan(float %x) {
565 ; CHECK-LABEL: @minnum_non_nan(
566 ; CHECK-NEXT: ret i1 true
568 %min = call float @llvm.minnum.f32(float 0.5, float %x)
569 %cmp = fcmp ord float %min, 1.0
573 define i1 @maxnum_non_nan(float %x) {
574 ; CHECK-LABEL: @maxnum_non_nan(
575 ; CHECK-NEXT: ret i1 false
577 %min = call float @llvm.maxnum.f32(float %x, float 42.0)
578 %cmp = fcmp uno float %min, 12.0
582 ; min(x, 0.5) == 1.0 --> false
584 define i1 @minnum_oeq_small_min_constant(float %x) {
585 ; CHECK-LABEL: @minnum_oeq_small_min_constant(
586 ; CHECK-NEXT: ret i1 false
588 %min = call float @llvm.minnum.f32(float %x, float 0.5)
589 %cmp = fcmp oeq float %min, 1.0
593 ; min(x, 0.5) > 1.0 --> false
595 define i1 @minnum_ogt_small_min_constant(float %x) {
596 ; CHECK-LABEL: @minnum_ogt_small_min_constant(
597 ; CHECK-NEXT: ret i1 false
599 %min = call float @llvm.minnum.f32(float %x, float 0.5)
600 %cmp = fcmp ogt float %min, 1.0
604 ; min(x, 0.5) >= 1.0 --> false
606 define i1 @minnum_oge_small_min_constant(float %x) {
607 ; CHECK-LABEL: @minnum_oge_small_min_constant(
608 ; CHECK-NEXT: ret i1 false
610 %min = call float @llvm.minnum.f32(float %x, float 0.5)
611 %cmp = fcmp oge float %min, 1.0
615 ; min(x, 0.5) == 1.0 --> false
617 define i1 @minnum_ueq_small_min_constant(float %x) {
618 ; CHECK-LABEL: @minnum_ueq_small_min_constant(
619 ; CHECK-NEXT: ret i1 false
621 %min = call float @llvm.minnum.f32(float %x, float 0.5)
622 %cmp = fcmp ueq float %min, 1.0
626 ; min(x, 0.5) > 1.0 --> false
628 define i1 @minnum_ugt_small_min_constant(float %x) {
629 ; CHECK-LABEL: @minnum_ugt_small_min_constant(
630 ; CHECK-NEXT: ret i1 false
632 %min = call float @llvm.minnum.f32(float %x, float 0.5)
633 %cmp = fcmp ugt float %min, 1.0
637 ; min(x, 0.5) >= 1.0 --> false
639 define <2 x i1> @minnum_uge_small_min_constant(<2 x float> %x) {
640 ; CHECK-LABEL: @minnum_uge_small_min_constant(
641 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
643 %min = call <2 x float> @llvm.minnum.v2f32(<2 x float> %x, <2 x float> <float 0.5, float 0.5>)
644 %cmp = fcmp uge <2 x float> %min, <float 1.0, float 1.0>
648 ; min(x, 0.5) < 1.0 --> true
650 define <2 x i1> @minnum_olt_small_min_constant(<2 x float> %x) {
651 ; CHECK-LABEL: @minnum_olt_small_min_constant(
652 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
654 %min = call <2 x float> @llvm.minnum.v2f32(<2 x float> %x, <2 x float> <float 0.5, float 0.5>)
655 %cmp = fcmp olt <2 x float> %min, <float 1.0, float 1.0>
659 ; min(x, 0.5) <= 1.0 --> true
661 define i1 @minnum_ole_small_min_constant(float %x) {
662 ; CHECK-LABEL: @minnum_ole_small_min_constant(
663 ; CHECK-NEXT: ret i1 true
665 %min = call float @llvm.minnum.f32(float %x, float 0.5)
666 %cmp = fcmp ole float %min, 1.0
670 ; min(x, 0.5) != 1.0 --> true
672 define i1 @minnum_one_small_min_constant(float %x) {
673 ; CHECK-LABEL: @minnum_one_small_min_constant(
674 ; CHECK-NEXT: ret i1 true
676 %min = call float @llvm.minnum.f32(float %x, float 0.5)
677 %cmp = fcmp one float %min, 1.0
681 ; min(x, 0.5) < 1.0 --> true
683 define i1 @minnum_ult_small_min_constant(float %x) {
684 ; CHECK-LABEL: @minnum_ult_small_min_constant(
685 ; CHECK-NEXT: ret i1 true
687 %min = call float @llvm.minnum.f32(float %x, float 0.5)
688 %cmp = fcmp ult float %min, 1.0
692 ; min(x, 0.5) <= 1.0 --> true
694 define i1 @minnum_ule_small_min_constant(float %x) {
695 ; CHECK-LABEL: @minnum_ule_small_min_constant(
696 ; CHECK-NEXT: ret i1 true
698 %min = call float @llvm.minnum.f32(float %x, float 0.5)
699 %cmp = fcmp ule float %min, 1.0
703 ; min(x, 0.5) != 1.0 --> true
705 define i1 @minnum_une_small_min_constant(float %x) {
706 ; CHECK-LABEL: @minnum_une_small_min_constant(
707 ; CHECK-NEXT: ret i1 true
709 %min = call float @llvm.minnum.f32(float %x, float 0.5)
710 %cmp = fcmp une float %min, 1.0
715 ; min(x, 1.0) != 1.0 --> ?
717 define i1 @minnum_une_equal_min_constant(float %x) {
718 ; CHECK-LABEL: @minnum_une_equal_min_constant(
719 ; CHECK-NEXT: [[MIN:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], float 1.000000e+00)
720 ; CHECK-NEXT: [[CMP:%.*]] = fcmp une float [[MIN]], 1.000000e+00
721 ; CHECK-NEXT: ret i1 [[CMP]]
723 %min = call float @llvm.minnum.f32(float %x, float 1.0)
724 %cmp = fcmp une float %min, 1.0
729 ; min(x, 2.0) != 1.0 --> ?
731 define i1 @minnum_une_large_min_constant(float %x) {
732 ; CHECK-LABEL: @minnum_une_large_min_constant(
733 ; CHECK-NEXT: [[MIN:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], float 2.000000e+00)
734 ; CHECK-NEXT: [[CMP:%.*]] = fcmp une float [[MIN]], 1.000000e+00
735 ; CHECK-NEXT: ret i1 [[CMP]]
737 %min = call float @llvm.minnum.f32(float %x, float 2.0)
738 %cmp = fcmp une float %min, 1.0
742 ; Partial negative test (the minnum simplifies):
743 ; min(x, NaN) != 1.0 --> x != 1.0
745 define i1 @minnum_une_nan_min_constant(float %x) {
746 ; CHECK-LABEL: @minnum_une_nan_min_constant(
747 ; CHECK-NEXT: [[CMP:%.*]] = fcmp une float [[X:%.*]], 1.000000e+00
748 ; CHECK-NEXT: ret i1 [[CMP]]
750 %min = call float @llvm.minnum.f32(float %x, float 0x7FF8000000000000)
751 %cmp = fcmp une float %min, 1.0
755 ; max(x, 1.5) == 1.0 --> false
757 define i1 @maxnum_oeq_large_max_constant(float %x) {
758 ; CHECK-LABEL: @maxnum_oeq_large_max_constant(
759 ; CHECK-NEXT: ret i1 false
761 %max = call float @llvm.maxnum.f32(float %x, float 1.5)
762 %cmp = fcmp oeq float %max, 1.0
766 ; max(x, 1.5) < 1.0 --> false
768 define i1 @maxnum_olt_large_max_constant(float %x) {
769 ; CHECK-LABEL: @maxnum_olt_large_max_constant(
770 ; CHECK-NEXT: ret i1 false
772 %max = call float @llvm.maxnum.f32(float %x, float 1.5)
773 %cmp = fcmp olt float %max, 1.0
777 ; max(x, 1.5) <= 1.0 --> false
779 define i1 @maxnum_ole_large_max_constant(float %x) {
780 ; CHECK-LABEL: @maxnum_ole_large_max_constant(
781 ; CHECK-NEXT: ret i1 false
783 %max = call float @llvm.maxnum.f32(float %x, float 1.5)
784 %cmp = fcmp ole float %max, 1.0
788 ; max(x, 1.5) == 1.0 --> false
790 define i1 @maxnum_ueq_large_max_constant(float %x) {
791 ; CHECK-LABEL: @maxnum_ueq_large_max_constant(
792 ; CHECK-NEXT: ret i1 false
794 %max = call float @llvm.maxnum.f32(float %x, float 1.5)
795 %cmp = fcmp ueq float %max, 1.0
799 ; max(x, 1.5) < 1.0 --> false
801 define i1 @maxnum_ult_large_max_constant(float %x) {
802 ; CHECK-LABEL: @maxnum_ult_large_max_constant(
803 ; CHECK-NEXT: ret i1 false
805 %max = call float @llvm.maxnum.f32(float %x, float 1.5)
806 %cmp = fcmp ult float %max, 1.0
810 ; max(x, 1.5) <= 1.0 --> false
812 define <2 x i1> @maxnum_ule_large_max_constant(<2 x float> %x) {
813 ; CHECK-LABEL: @maxnum_ule_large_max_constant(
814 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
816 %max = call <2 x float> @llvm.maxnum.v2f32(<2 x float> %x, <2 x float> <float 1.5, float 1.5>)
817 %cmp = fcmp ule <2 x float> %max, <float 1.0, float 1.0>
821 ; max(x, 1.5) > 1.0 --> true
823 define <2 x i1> @maxnum_ogt_large_max_constant(<2 x float> %x) {
824 ; CHECK-LABEL: @maxnum_ogt_large_max_constant(
825 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
827 %max = call <2 x float> @llvm.maxnum.v2f32(<2 x float> %x, <2 x float> <float 1.5, float 1.5>)
828 %cmp = fcmp ogt <2 x float> %max, <float 1.0, float 1.0>
832 ; max(x, 1.5) >= 1.0 --> true
834 define i1 @maxnum_oge_large_max_constant(float %x) {
835 ; CHECK-LABEL: @maxnum_oge_large_max_constant(
836 ; CHECK-NEXT: ret i1 true
838 %max = call float @llvm.maxnum.f32(float %x, float 1.5)
839 %cmp = fcmp oge float %max, 1.0
843 ; max(x, 1.5) != 1.0 --> true
845 define i1 @maxnum_one_large_max_constant(float %x) {
846 ; CHECK-LABEL: @maxnum_one_large_max_constant(
847 ; CHECK-NEXT: ret i1 true
849 %max = call float @llvm.maxnum.f32(float %x, float 1.5)
850 %cmp = fcmp one float %max, 1.0
854 ; max(x, 1.5) > 1.0 --> true
856 define i1 @maxnum_ugt_large_max_constant(float %x) {
857 ; CHECK-LABEL: @maxnum_ugt_large_max_constant(
858 ; CHECK-NEXT: ret i1 true
860 %max = call float @llvm.maxnum.f32(float %x, float 1.5)
861 %cmp = fcmp ugt float %max, 1.0
865 ; max(x, 1.5) >= 1.0 --> true
867 define i1 @maxnum_uge_large_max_constant(float %x) {
868 ; CHECK-LABEL: @maxnum_uge_large_max_constant(
869 ; CHECK-NEXT: ret i1 true
871 %max = call float @llvm.maxnum.f32(float %x, float 1.5)
872 %cmp = fcmp uge float %max, 1.0
876 ; max(x, 1.5) != 1.0 --> true
878 define i1 @maxnum_une_large_max_constant(float %x) {
879 ; CHECK-LABEL: @maxnum_une_large_max_constant(
880 ; CHECK-NEXT: ret i1 true
882 %max = call float @llvm.maxnum.f32(float %x, float 1.5)
883 %cmp = fcmp une float %max, 1.0
888 ; max(x, 1.0) != 1.0 --> ?
890 define i1 @maxnum_une_equal_max_constant(float %x) {
891 ; CHECK-LABEL: @maxnum_une_equal_max_constant(
892 ; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float 1.000000e+00)
893 ; CHECK-NEXT: [[CMP:%.*]] = fcmp une float [[MAX]], 1.000000e+00
894 ; CHECK-NEXT: ret i1 [[CMP]]
896 %max = call float @llvm.maxnum.f32(float %x, float 1.0)
897 %cmp = fcmp une float %max, 1.0
902 ; max(x, 0.5) != 1.0 --> ?
904 define i1 @maxnum_une_small_max_constant(float %x) {
905 ; CHECK-LABEL: @maxnum_une_small_max_constant(
906 ; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float 5.000000e-01)
907 ; CHECK-NEXT: [[CMP:%.*]] = fcmp une float [[MAX]], 1.000000e+00
908 ; CHECK-NEXT: ret i1 [[CMP]]
910 %max = call float @llvm.maxnum.f32(float %x, float 0.5)
911 %cmp = fcmp une float %max, 1.0
915 ; Partial negative test (the maxnum simplifies):
916 ; max(x, NaN) != 1.0 --> x != 1.0
918 define i1 @maxnum_une_nan_max_constant(float %x) {
919 ; CHECK-LABEL: @maxnum_une_nan_max_constant(
920 ; CHECK-NEXT: [[CMP:%.*]] = fcmp une float [[X:%.*]], 1.000000e+00
921 ; CHECK-NEXT: ret i1 [[CMP]]
923 %max = call float @llvm.maxnum.f32(float %x, float 0x7FF8000000000000)
924 %cmp = fcmp une float %max, 1.0
928 define i1 @known_positive_olt_with_negative_constant(double %a) {
929 ; CHECK-LABEL: @known_positive_olt_with_negative_constant(
930 ; CHECK-NEXT: ret i1 false
932 %call = call double @llvm.fabs.f64(double %a)
933 %cmp = fcmp olt double %call, -1.0
937 define <2 x i1> @known_positive_ole_with_negative_constant_splat_vec(<2 x i32> %a) {
938 ; CHECK-LABEL: @known_positive_ole_with_negative_constant_splat_vec(
939 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
941 %call = uitofp <2 x i32> %a to <2 x double>
942 %cmp = fcmp ole <2 x double> %call, <double -2.0, double -2.0>
946 define i1 @known_positive_ugt_with_negative_constant(i32 %a) {
947 ; CHECK-LABEL: @known_positive_ugt_with_negative_constant(
948 ; CHECK-NEXT: ret i1 true
950 %call = uitofp i32 %a to float
951 %cmp = fcmp ugt float %call, -3.0
955 define <2 x i1> @known_positive_uge_with_negative_constant_splat_vec(<2 x float> %a) {
956 ; CHECK-LABEL: @known_positive_uge_with_negative_constant_splat_vec(
957 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
959 %call = call <2 x float> @llvm.fabs.v2f32(<2 x float> %a)
960 %cmp = fcmp uge <2 x float> %call, <float -4.0, float -4.0>
964 define i1 @known_positive_oeq_with_negative_constant(half %a) {
965 ; CHECK-LABEL: @known_positive_oeq_with_negative_constant(
966 ; CHECK-NEXT: ret i1 false
968 %call = call half @llvm.fabs.f16(half %a)
969 %cmp = fcmp oeq half %call, -5.0
973 define <2 x i1> @known_positive_une_with_negative_constant_splat_vec(<2 x i32> %a) {
974 ; CHECK-LABEL: @known_positive_une_with_negative_constant_splat_vec(
975 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
977 %call = uitofp <2 x i32> %a to <2 x half>
978 %cmp = fcmp une <2 x half> %call, <half -6.0, half -6.0>
982 define i1 @nonans1(double %in1, double %in2) {
983 ; CHECK-LABEL: @nonans1(
984 ; CHECK-NEXT: ret i1 false
986 %cmp = fcmp nnan uno double %in1, %in2
990 define i1 @nonans2(double %in1, double %in2) {
991 ; CHECK-LABEL: @nonans2(
992 ; CHECK-NEXT: ret i1 true
994 %cmp = fcmp nnan ord double %in1, %in2
998 define <2 x i1> @orderedCompareWithNaNVector(<2 x double> %A) {
999 ; CHECK-LABEL: @orderedCompareWithNaNVector(
1000 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1002 %cmp = fcmp olt <2 x double> %A, <double 0xFFFFFFFFFFFFFFFF, double 0xFFFFFFFFFFFFFFFF>
1006 define <2 x i1> @orderedCompareWithNaNVector_undef_elt(<2 x double> %A) {
1007 ; CHECK-LABEL: @orderedCompareWithNaNVector_undef_elt(
1008 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1010 %cmp = fcmp olt <2 x double> %A, <double 0xFFFFFFFFFFFFFFFF, double undef>
1014 define <2 x i1> @unorderedCompareWithNaNVector_undef_elt(<2 x double> %A) {
1015 ; CHECK-LABEL: @unorderedCompareWithNaNVector_undef_elt(
1016 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1018 %cmp = fcmp ult <2 x double> %A, <double undef, double 0xFFFFFFFFFFFFFFFF>