floating-point-compare.ll
27.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instsimplify -S | FileCheck %s
; Infinity
define i1 @inf0(double %arg) {
; CHECK-LABEL: @inf0(
; CHECK-NEXT: ret i1 false
;
%tmp = fcmp ogt double %arg, 0x7FF0000000000000
ret i1 %tmp
}
define i1 @inf1(double %arg) {
; CHECK-LABEL: @inf1(
; CHECK-NEXT: ret i1 true
;
%tmp = fcmp ule double %arg, 0x7FF0000000000000
ret i1 %tmp
}
; Negative infinity
define i1 @ninf0(double %arg) {
; CHECK-LABEL: @ninf0(
; CHECK-NEXT: ret i1 false
;
%tmp = fcmp olt double %arg, 0xFFF0000000000000
ret i1 %tmp
}
define i1 @ninf1(double %arg) {
; CHECK-LABEL: @ninf1(
; CHECK-NEXT: ret i1 true
;
%tmp = fcmp uge double %arg, 0xFFF0000000000000
ret i1 %tmp
}
; NaNs
define i1 @nan0(double %arg) {
; CHECK-LABEL: @nan0(
; CHECK-NEXT: ret i1 false
;
%tmp = fcmp ord double %arg, 0x7FF00000FFFFFFFF
ret i1 %tmp
}
define i1 @nan1(double %arg) {
; CHECK-LABEL: @nan1(
; CHECK-NEXT: ret i1 false
;
%tmp = fcmp oeq double %arg, 0x7FF00000FFFFFFFF
ret i1 %tmp
}
define i1 @nan2(double %arg) {
; CHECK-LABEL: @nan2(
; CHECK-NEXT: ret i1 false
;
%tmp = fcmp olt double %arg, 0x7FF00000FFFFFFFF
ret i1 %tmp
}
define i1 @nan3(double %arg) {
; CHECK-LABEL: @nan3(
; CHECK-NEXT: ret i1 true
;
%tmp = fcmp uno double %arg, 0x7FF00000FFFFFFFF
ret i1 %tmp
}
define i1 @nan4(double %arg) {
; CHECK-LABEL: @nan4(
; CHECK-NEXT: ret i1 true
;
%tmp = fcmp une double %arg, 0x7FF00000FFFFFFFF
ret i1 %tmp
}
define i1 @nan5(double %arg) {
; CHECK-LABEL: @nan5(
; CHECK-NEXT: ret i1 true
;
%tmp = fcmp ult double %arg, 0x7FF00000FFFFFFFF
ret i1 %tmp
}
; Negative NaN.
define i1 @nnan0(double %arg) {
; CHECK-LABEL: @nnan0(
; CHECK-NEXT: ret i1 false
;
%tmp = fcmp ord double %arg, 0xFFF00000FFFFFFFF
ret i1 %tmp
}
define i1 @nnan1(double %arg) {
; CHECK-LABEL: @nnan1(
; CHECK-NEXT: ret i1 false
;
%tmp = fcmp oeq double %arg, 0xFFF00000FFFFFFFF
ret i1 %tmp
}
define i1 @nnan2(double %arg) {
; CHECK-LABEL: @nnan2(
; CHECK-NEXT: ret i1 false
;
%tmp = fcmp olt double %arg, 0xFFF00000FFFFFFFF
ret i1 %tmp
}
define i1 @nnan3(double %arg) {
; CHECK-LABEL: @nnan3(
; CHECK-NEXT: ret i1 true
;
%tmp = fcmp uno double %arg, 0xFFF00000FFFFFFFF
ret i1 %tmp
}
define i1 @nnan4(double %arg) {
; CHECK-LABEL: @nnan4(
; CHECK-NEXT: ret i1 true
;
%tmp = fcmp une double %arg, 0xFFF00000FFFFFFFF
ret i1 %tmp
}
define i1 @nnan5(double %arg) {
; CHECK-LABEL: @nnan5(
; CHECK-NEXT: ret i1 true
;
%tmp = fcmp ult double %arg, 0xFFF00000FFFFFFFF
ret i1 %tmp
}
; Negative zero.
define i1 @nzero0() {
; CHECK-LABEL: @nzero0(
; CHECK-NEXT: ret i1 true
;
%tmp = fcmp oeq double 0.0, -0.0
ret i1 %tmp
}
define i1 @nzero1() {
; CHECK-LABEL: @nzero1(
; CHECK-NEXT: ret i1 false
;
%tmp = fcmp ogt double 0.0, -0.0
ret i1 %tmp
}
; No enlightenment here.
define i1 @one_with_self(double %arg) {
; CHECK-LABEL: @one_with_self(
; CHECK-NEXT: ret i1 false
;
%tmp = fcmp one double %arg, %arg
ret i1 %tmp
}
; These tests choose arbitrarily between float and double,
; and between uge and olt, to give reasonble coverage
; without combinatorial explosion.
declare half @llvm.fabs.f16(half)
declare float @llvm.fabs.f32(float)
declare double @llvm.fabs.f64(double)
declare <2 x float> @llvm.fabs.v2f32(<2 x float>)
declare <3 x float> @llvm.fabs.v3f32(<3 x float>)
declare <2 x double> @llvm.fabs.v2f64(<2 x double>)
declare float @llvm.sqrt.f32(float)
declare double @llvm.powi.f64(double,i32)
declare float @llvm.exp.f32(float)
declare float @llvm.minnum.f32(float, float)
declare <2 x float> @llvm.minnum.v2f32(<2 x float>, <2 x float>)
declare float @llvm.maxnum.f32(float, float)
declare <2 x float> @llvm.maxnum.v2f32(<2 x float>, <2 x float>)
declare float @llvm.maximum.f32(float, float)
declare double @llvm.exp2.f64(double)
declare float @llvm.fma.f32(float,float,float)
declare void @expect_equal(i1,i1)
define i1 @orderedLessZeroTree(float,float,float,float) {
; CHECK-LABEL: @orderedLessZeroTree(
; CHECK-NEXT: ret i1 true
;
%square = fmul float %0, %0
%abs = call float @llvm.fabs.f32(float %1)
%sqrt = call float @llvm.sqrt.f32(float %2)
%fma = call float @llvm.fma.f32(float %3, float %3, float %sqrt)
%div = fdiv float %square, %abs
%rem = frem float %sqrt, %fma
%add = fadd float %div, %rem
%uge = fcmp uge float %add, 0.000000e+00
ret i1 %uge
}
define i1 @orderedLessZeroExpExt(float) {
; CHECK-LABEL: @orderedLessZeroExpExt(
; CHECK-NEXT: ret i1 true
;
%a = call float @llvm.exp.f32(float %0)
%b = fpext float %a to double
%uge = fcmp uge double %b, 0.000000e+00
ret i1 %uge
}
define i1 @orderedLessZeroExp2Trunc(double) {
; CHECK-LABEL: @orderedLessZeroExp2Trunc(
; CHECK-NEXT: ret i1 false
;
%a = call double @llvm.exp2.f64(double %0)
%b = fptrunc double %a to float
%olt = fcmp olt float %b, 0.000000e+00
ret i1 %olt
}
define i1 @orderedLessZeroPowi(double,double) {
; CHECK-LABEL: @orderedLessZeroPowi(
; CHECK-NEXT: ret i1 false
;
; Even constant exponent
%a = call double @llvm.powi.f64(double %0, i32 2)
%square = fmul double %1, %1
; Odd constant exponent with provably non-negative base
%b = call double @llvm.powi.f64(double %square, i32 3)
%c = fadd double %a, %b
%olt = fcmp olt double %b, 0.000000e+00
ret i1 %olt
}
define i1 @UIToFP_is_nan_or_positive_or_zero(i32 %x) {
; CHECK-LABEL: @UIToFP_is_nan_or_positive_or_zero(
; CHECK-NEXT: ret i1 true
;
%a = uitofp i32 %x to float
%r = fcmp uge float %a, 0.000000e+00
ret i1 %r
}
define <2 x i1> @UIToFP_is_nan_or_positive_or_zero_vec(<2 x i32> %x) {
; CHECK-LABEL: @UIToFP_is_nan_or_positive_or_zero_vec(
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%a = uitofp <2 x i32> %x to <2 x float>
%r = fcmp uge <2 x float> %a, zeroinitializer
ret <2 x i1> %r
}
define i1 @UIToFP_is_positive_or_zero(i32 %x) {
; CHECK-LABEL: @UIToFP_is_positive_or_zero(
; CHECK-NEXT: ret i1 true
;
%a = uitofp i32 %x to float
%r = fcmp oge float %a, 0.000000e+00
ret i1 %r
}
define <2 x i1> @UIToFP_is_positive_or_zero_vec(<2 x i32> %x) {
; CHECK-LABEL: @UIToFP_is_positive_or_zero_vec(
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%a = uitofp <2 x i32> %x to <2 x float>
%r = fcmp oge <2 x float> %a, zeroinitializer
ret <2 x i1> %r
}
define i1 @UIToFP_nnan_is_positive_or_zero(i32 %x) {
; CHECK-LABEL: @UIToFP_nnan_is_positive_or_zero(
; CHECK-NEXT: ret i1 true
;
%a = uitofp i32 %x to float
%r = fcmp nnan oge float %a, 0.000000e+00
ret i1 %r
}
define <2 x i1> @UIToFP_nnan_is_positive_or_zero_vec(<2 x i32> %x) {
; CHECK-LABEL: @UIToFP_nnan_is_positive_or_zero_vec(
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%a = uitofp <2 x i32> %x to <2 x float>
%r = fcmp nnan oge <2 x float> %a, zeroinitializer
ret <2 x i1> %r
}
define i1 @UIToFP_is_not_negative(i32 %x) {
; CHECK-LABEL: @UIToFP_is_not_negative(
; CHECK-NEXT: ret i1 false
;
%a = uitofp i32 %x to float
%r = fcmp olt float %a, 0.000000e+00
ret i1 %r
}
define <2 x i1> @UIToFP_is_not_negative_vec(<2 x i32> %x) {
; CHECK-LABEL: @UIToFP_is_not_negative_vec(
; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%a = uitofp <2 x i32> %x to <2 x float>
%r = fcmp olt <2 x float> %a, zeroinitializer
ret <2 x i1> %r
}
; No FMF are required for this transform.
define i1 @UIToFP_is_not_negative_or_nan(i32 %x) {
; CHECK-LABEL: @UIToFP_is_not_negative_or_nan(
; CHECK-NEXT: ret i1 false
;
%a = uitofp i32 %x to float
%r = fcmp ult float %a, 0.000000e+00
ret i1 %r
}
define <2 x i1> @UIToFP_is_not_negative_or_nan_vec(<2 x i32> %x) {
; CHECK-LABEL: @UIToFP_is_not_negative_or_nan_vec(
; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%a = uitofp <2 x i32> %x to <2 x float>
%r = fcmp ult <2 x float> %a, zeroinitializer
ret <2 x i1> %r
}
define i1 @UIToFP_nnan_is_not_negative(i32 %x) {
; CHECK-LABEL: @UIToFP_nnan_is_not_negative(
; CHECK-NEXT: ret i1 false
;
%a = uitofp i32 %x to float
%r = fcmp nnan ult float %a, 0.000000e+00
ret i1 %r
}
define <2 x i1> @UIToFP_nnan_is_not_negative_vec(<2 x i32> %x) {
; CHECK-LABEL: @UIToFP_nnan_is_not_negative_vec(
; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%a = uitofp <2 x i32> %x to <2 x float>
%r = fcmp nnan ult <2 x float> %a, zeroinitializer
ret <2 x i1> %r
}
define i1 @fabs_is_nan_or_positive_or_zero(double %x) {
; CHECK-LABEL: @fabs_is_nan_or_positive_or_zero(
; CHECK-NEXT: ret i1 true
;
%fabs = tail call double @llvm.fabs.f64(double %x)
%cmp = fcmp uge double %fabs, 0.0
ret i1 %cmp
}
define <2 x i1> @fabs_is_nan_or_positive_or_zero_vec(<2 x double> %x) {
; CHECK-LABEL: @fabs_is_nan_or_positive_or_zero_vec(
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%fabs = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
%cmp = fcmp uge <2 x double> %fabs, zeroinitializer
ret <2 x i1> %cmp
}
define i1 @fabs_nnan_is_positive_or_zero(double %x) {
; CHECK-LABEL: @fabs_nnan_is_positive_or_zero(
; CHECK-NEXT: ret i1 true
;
%fabs = tail call nnan double @llvm.fabs.f64(double %x)
%cmp = fcmp oge double %fabs, 0.0
ret i1 %cmp
}
define <2 x i1> @fabs_nnan_is_positive_or_zero_vec(<2 x double> %x) {
; CHECK-LABEL: @fabs_nnan_is_positive_or_zero_vec(
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%fabs = tail call nnan <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
%cmp = fcmp oge <2 x double> %fabs, zeroinitializer
ret <2 x i1> %cmp
}
define i1 @fabs_fcmp-nnan_is_positive_or_zero(double %x) {
; CHECK-LABEL: @fabs_fcmp-nnan_is_positive_or_zero(
; CHECK-NEXT: ret i1 true
;
%fabs = tail call double @llvm.fabs.f64(double %x)
%cmp = fcmp nnan oge double %fabs, 0.0
ret i1 %cmp
}
define <2 x i1> @fabs_fcmp-nnan_is_positive_or_zero_vec(<2 x double> %x) {
; CHECK-LABEL: @fabs_fcmp-nnan_is_positive_or_zero_vec(
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%fabs = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
%cmp = fcmp nnan oge <2 x double> %fabs, zeroinitializer
ret <2 x i1> %cmp
}
define i1 @fabs_is_not_negative(double %x) {
; CHECK-LABEL: @fabs_is_not_negative(
; CHECK-NEXT: ret i1 false
;
%fabs = tail call double @llvm.fabs.f64(double %x)
%cmp = fcmp olt double %fabs, 0.0
ret i1 %cmp
}
define <2 x i1> @fabs_is_not_negative_vec(<2 x double> %x) {
; CHECK-LABEL: @fabs_is_not_negative_vec(
; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%fabs = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
%cmp = fcmp olt <2 x double> %fabs, zeroinitializer
ret <2 x i1> %cmp
}
define i1 @fabs_nnan_is_not_negative(double %x) {
; CHECK-LABEL: @fabs_nnan_is_not_negative(
; CHECK-NEXT: ret i1 false
;
%fabs = tail call nnan double @llvm.fabs.f64(double %x)
%cmp = fcmp ult double %fabs, 0.0
ret i1 %cmp
}
define <2 x i1> @fabs_nnan_is_not_negative_vec(<2 x double> %x) {
; CHECK-LABEL: @fabs_nnan_is_not_negative_vec(
; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%fabs = tail call nnan <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
%cmp = fcmp ult <2 x double> %fabs, zeroinitializer
ret <2 x i1> %cmp
}
define i1 @fabs_fcmp-nnan_is_not_negative(double %x) {
; CHECK-LABEL: @fabs_fcmp-nnan_is_not_negative(
; CHECK-NEXT: ret i1 false
;
%fabs = tail call double @llvm.fabs.f64(double %x)
%cmp = fcmp nnan ult double %fabs, 0.0
ret i1 %cmp
}
define <2 x i1> @fabs_fcmp-nnan_is_not_negative_vec(<2 x double> %x) {
; CHECK-LABEL: @fabs_fcmp-nnan_is_not_negative_vec(
; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%fabs = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
%cmp = fcmp nnan ult <2 x double> %fabs, zeroinitializer
ret <2 x i1> %cmp
}
define <2 x i1> @fabs_is_not_negative_negzero(<2 x float> %V) {
; CHECK-LABEL: @fabs_is_not_negative_negzero(
; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%abs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %V)
%cmp = fcmp olt <2 x float> %abs, <float -0.0, float -0.0>
ret <2 x i1> %cmp
}
define <2 x i1> @fabs_is_not_negative_poszero(<2 x float> %V) {
; CHECK-LABEL: @fabs_is_not_negative_poszero(
; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%abs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %V)
%cmp = fcmp olt <2 x float> %abs, <float 0.0, float 0.0>
ret <2 x i1> %cmp
}
define <2 x i1> @fabs_is_not_negative_anyzero(<2 x float> %V) {
; CHECK-LABEL: @fabs_is_not_negative_anyzero(
; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%abs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %V)
%cmp = fcmp olt <2 x float> %abs, <float 0.0, float -0.0>
ret <2 x i1> %cmp
}
define <3 x i1> @fabs_is_not_negative_negzero_undef(<3 x float> %V) {
; CHECK-LABEL: @fabs_is_not_negative_negzero_undef(
; CHECK-NEXT: ret <3 x i1> zeroinitializer
;
%abs = call <3 x float> @llvm.fabs.v3f32(<3 x float> %V)
%cmp = fcmp olt <3 x float> %abs, <float -0.0, float -0.0, float undef>
ret <3 x i1> %cmp
}
define <3 x i1> @fabs_is_not_negative_poszero_undef(<3 x float> %V) {
; CHECK-LABEL: @fabs_is_not_negative_poszero_undef(
; CHECK-NEXT: ret <3 x i1> zeroinitializer
;
%abs = call <3 x float> @llvm.fabs.v3f32(<3 x float> %V)
%cmp = fcmp olt <3 x float> %abs, <float 0.0, float 0.0, float undef>
ret <3 x i1> %cmp
}
define <3 x i1> @fabs_is_not_negative_anyzero_undef(<3 x float> %V) {
; CHECK-LABEL: @fabs_is_not_negative_anyzero_undef(
; CHECK-NEXT: ret <3 x i1> zeroinitializer
;
%abs = call <3 x float> @llvm.fabs.v3f32(<3 x float> %V)
%cmp = fcmp olt <3 x float> %abs, <float 0.0, float -0.0, float undef>
ret <3 x i1> %cmp
}
define i1 @orderedLessZeroSelect(float, float) {
; CHECK-LABEL: @orderedLessZeroSelect(
; CHECK-NEXT: ret i1 true
;
%a = call float @llvm.exp.f32(float %0)
%b = call float @llvm.fabs.f32(float %1)
%c = fcmp olt float %0, %1
%d = select i1 %c, float %a, float %b
%e = fadd float %d, 1.0
%uge = fcmp uge float %e, 0.000000e+00
ret i1 %uge
}
define i1 @orderedLessZeroMinNum(float, float) {
; CHECK-LABEL: @orderedLessZeroMinNum(
; CHECK-NEXT: ret i1 true
;
%a = call float @llvm.exp.f32(float %0)
%b = call float @llvm.fabs.f32(float %1)
%c = call float @llvm.minnum.f32(float %a, float %b)
%uge = fcmp uge float %c, 0.000000e+00
ret i1 %uge
}
; PR37776: https://bugs.llvm.org/show_bug.cgi?id=37776
; exp() may return nan, leaving %1 as the unknown result, so we can't simplify.
define i1 @orderedLessZeroMaxNum(float, float) {
; CHECK-LABEL: @orderedLessZeroMaxNum(
; CHECK-NEXT: [[A:%.*]] = call float @llvm.exp.f32(float [[TMP0:%.*]])
; CHECK-NEXT: [[B:%.*]] = call float @llvm.maxnum.f32(float [[A]], float [[TMP1:%.*]])
; CHECK-NEXT: [[UGE:%.*]] = fcmp uge float [[B]], 0.000000e+00
; CHECK-NEXT: ret i1 [[UGE]]
;
%a = call float @llvm.exp.f32(float %0)
%b = call float @llvm.maxnum.f32(float %a, float %1)
%uge = fcmp uge float %b, 0.000000e+00
ret i1 %uge
}
; But using maximum, we can simplify, since the NaN would be propagated
define i1 @orderedLessZeroMaximum(float, float) {
; CHECK-LABEL: @orderedLessZeroMaximum(
; CHECK-NEXT: ret i1 true
;
%a = call float @llvm.exp.f32(float %0)
%b = call float @llvm.maximum.f32(float %a, float %1)
%uge = fcmp uge float %b, 0.000000e+00
ret i1 %uge
}
define i1 @minnum_non_nan(float %x) {
; CHECK-LABEL: @minnum_non_nan(
; CHECK-NEXT: ret i1 true
;
%min = call float @llvm.minnum.f32(float 0.5, float %x)
%cmp = fcmp ord float %min, 1.0
ret i1 %cmp
}
define i1 @maxnum_non_nan(float %x) {
; CHECK-LABEL: @maxnum_non_nan(
; CHECK-NEXT: ret i1 false
;
%min = call float @llvm.maxnum.f32(float %x, float 42.0)
%cmp = fcmp uno float %min, 12.0
ret i1 %cmp
}
; min(x, 0.5) == 1.0 --> false
define i1 @minnum_oeq_small_min_constant(float %x) {
; CHECK-LABEL: @minnum_oeq_small_min_constant(
; CHECK-NEXT: ret i1 false
;
%min = call float @llvm.minnum.f32(float %x, float 0.5)
%cmp = fcmp oeq float %min, 1.0
ret i1 %cmp
}
; min(x, 0.5) > 1.0 --> false
define i1 @minnum_ogt_small_min_constant(float %x) {
; CHECK-LABEL: @minnum_ogt_small_min_constant(
; CHECK-NEXT: ret i1 false
;
%min = call float @llvm.minnum.f32(float %x, float 0.5)
%cmp = fcmp ogt float %min, 1.0
ret i1 %cmp
}
; min(x, 0.5) >= 1.0 --> false
define i1 @minnum_oge_small_min_constant(float %x) {
; CHECK-LABEL: @minnum_oge_small_min_constant(
; CHECK-NEXT: ret i1 false
;
%min = call float @llvm.minnum.f32(float %x, float 0.5)
%cmp = fcmp oge float %min, 1.0
ret i1 %cmp
}
; min(x, 0.5) == 1.0 --> false
define i1 @minnum_ueq_small_min_constant(float %x) {
; CHECK-LABEL: @minnum_ueq_small_min_constant(
; CHECK-NEXT: ret i1 false
;
%min = call float @llvm.minnum.f32(float %x, float 0.5)
%cmp = fcmp ueq float %min, 1.0
ret i1 %cmp
}
; min(x, 0.5) > 1.0 --> false
define i1 @minnum_ugt_small_min_constant(float %x) {
; CHECK-LABEL: @minnum_ugt_small_min_constant(
; CHECK-NEXT: ret i1 false
;
%min = call float @llvm.minnum.f32(float %x, float 0.5)
%cmp = fcmp ugt float %min, 1.0
ret i1 %cmp
}
; min(x, 0.5) >= 1.0 --> false
define <2 x i1> @minnum_uge_small_min_constant(<2 x float> %x) {
; CHECK-LABEL: @minnum_uge_small_min_constant(
; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%min = call <2 x float> @llvm.minnum.v2f32(<2 x float> %x, <2 x float> <float 0.5, float 0.5>)
%cmp = fcmp uge <2 x float> %min, <float 1.0, float 1.0>
ret <2 x i1> %cmp
}
; min(x, 0.5) < 1.0 --> true
define <2 x i1> @minnum_olt_small_min_constant(<2 x float> %x) {
; CHECK-LABEL: @minnum_olt_small_min_constant(
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%min = call <2 x float> @llvm.minnum.v2f32(<2 x float> %x, <2 x float> <float 0.5, float 0.5>)
%cmp = fcmp olt <2 x float> %min, <float 1.0, float 1.0>
ret <2 x i1> %cmp
}
; min(x, 0.5) <= 1.0 --> true
define i1 @minnum_ole_small_min_constant(float %x) {
; CHECK-LABEL: @minnum_ole_small_min_constant(
; CHECK-NEXT: ret i1 true
;
%min = call float @llvm.minnum.f32(float %x, float 0.5)
%cmp = fcmp ole float %min, 1.0
ret i1 %cmp
}
; min(x, 0.5) != 1.0 --> true
define i1 @minnum_one_small_min_constant(float %x) {
; CHECK-LABEL: @minnum_one_small_min_constant(
; CHECK-NEXT: ret i1 true
;
%min = call float @llvm.minnum.f32(float %x, float 0.5)
%cmp = fcmp one float %min, 1.0
ret i1 %cmp
}
; min(x, 0.5) < 1.0 --> true
define i1 @minnum_ult_small_min_constant(float %x) {
; CHECK-LABEL: @minnum_ult_small_min_constant(
; CHECK-NEXT: ret i1 true
;
%min = call float @llvm.minnum.f32(float %x, float 0.5)
%cmp = fcmp ult float %min, 1.0
ret i1 %cmp
}
; min(x, 0.5) <= 1.0 --> true
define i1 @minnum_ule_small_min_constant(float %x) {
; CHECK-LABEL: @minnum_ule_small_min_constant(
; CHECK-NEXT: ret i1 true
;
%min = call float @llvm.minnum.f32(float %x, float 0.5)
%cmp = fcmp ule float %min, 1.0
ret i1 %cmp
}
; min(x, 0.5) != 1.0 --> true
define i1 @minnum_une_small_min_constant(float %x) {
; CHECK-LABEL: @minnum_une_small_min_constant(
; CHECK-NEXT: ret i1 true
;
%min = call float @llvm.minnum.f32(float %x, float 0.5)
%cmp = fcmp une float %min, 1.0
ret i1 %cmp
}
; Negative test:
; min(x, 1.0) != 1.0 --> ?
define i1 @minnum_une_equal_min_constant(float %x) {
; CHECK-LABEL: @minnum_une_equal_min_constant(
; CHECK-NEXT: [[MIN:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], float 1.000000e+00)
; CHECK-NEXT: [[CMP:%.*]] = fcmp une float [[MIN]], 1.000000e+00
; CHECK-NEXT: ret i1 [[CMP]]
;
%min = call float @llvm.minnum.f32(float %x, float 1.0)
%cmp = fcmp une float %min, 1.0
ret i1 %cmp
}
; Negative test:
; min(x, 2.0) != 1.0 --> ?
define i1 @minnum_une_large_min_constant(float %x) {
; CHECK-LABEL: @minnum_une_large_min_constant(
; CHECK-NEXT: [[MIN:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], float 2.000000e+00)
; CHECK-NEXT: [[CMP:%.*]] = fcmp une float [[MIN]], 1.000000e+00
; CHECK-NEXT: ret i1 [[CMP]]
;
%min = call float @llvm.minnum.f32(float %x, float 2.0)
%cmp = fcmp une float %min, 1.0
ret i1 %cmp
}
; Partial negative test (the minnum simplifies):
; min(x, NaN) != 1.0 --> x != 1.0
define i1 @minnum_une_nan_min_constant(float %x) {
; CHECK-LABEL: @minnum_une_nan_min_constant(
; CHECK-NEXT: [[CMP:%.*]] = fcmp une float [[X:%.*]], 1.000000e+00
; CHECK-NEXT: ret i1 [[CMP]]
;
%min = call float @llvm.minnum.f32(float %x, float 0x7FF8000000000000)
%cmp = fcmp une float %min, 1.0
ret i1 %cmp
}
; max(x, 1.5) == 1.0 --> false
define i1 @maxnum_oeq_large_max_constant(float %x) {
; CHECK-LABEL: @maxnum_oeq_large_max_constant(
; CHECK-NEXT: ret i1 false
;
%max = call float @llvm.maxnum.f32(float %x, float 1.5)
%cmp = fcmp oeq float %max, 1.0
ret i1 %cmp
}
; max(x, 1.5) < 1.0 --> false
define i1 @maxnum_olt_large_max_constant(float %x) {
; CHECK-LABEL: @maxnum_olt_large_max_constant(
; CHECK-NEXT: ret i1 false
;
%max = call float @llvm.maxnum.f32(float %x, float 1.5)
%cmp = fcmp olt float %max, 1.0
ret i1 %cmp
}
; max(x, 1.5) <= 1.0 --> false
define i1 @maxnum_ole_large_max_constant(float %x) {
; CHECK-LABEL: @maxnum_ole_large_max_constant(
; CHECK-NEXT: ret i1 false
;
%max = call float @llvm.maxnum.f32(float %x, float 1.5)
%cmp = fcmp ole float %max, 1.0
ret i1 %cmp
}
; max(x, 1.5) == 1.0 --> false
define i1 @maxnum_ueq_large_max_constant(float %x) {
; CHECK-LABEL: @maxnum_ueq_large_max_constant(
; CHECK-NEXT: ret i1 false
;
%max = call float @llvm.maxnum.f32(float %x, float 1.5)
%cmp = fcmp ueq float %max, 1.0
ret i1 %cmp
}
; max(x, 1.5) < 1.0 --> false
define i1 @maxnum_ult_large_max_constant(float %x) {
; CHECK-LABEL: @maxnum_ult_large_max_constant(
; CHECK-NEXT: ret i1 false
;
%max = call float @llvm.maxnum.f32(float %x, float 1.5)
%cmp = fcmp ult float %max, 1.0
ret i1 %cmp
}
; max(x, 1.5) <= 1.0 --> false
define <2 x i1> @maxnum_ule_large_max_constant(<2 x float> %x) {
; CHECK-LABEL: @maxnum_ule_large_max_constant(
; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%max = call <2 x float> @llvm.maxnum.v2f32(<2 x float> %x, <2 x float> <float 1.5, float 1.5>)
%cmp = fcmp ule <2 x float> %max, <float 1.0, float 1.0>
ret <2 x i1> %cmp
}
; max(x, 1.5) > 1.0 --> true
define <2 x i1> @maxnum_ogt_large_max_constant(<2 x float> %x) {
; CHECK-LABEL: @maxnum_ogt_large_max_constant(
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%max = call <2 x float> @llvm.maxnum.v2f32(<2 x float> %x, <2 x float> <float 1.5, float 1.5>)
%cmp = fcmp ogt <2 x float> %max, <float 1.0, float 1.0>
ret <2 x i1> %cmp
}
; max(x, 1.5) >= 1.0 --> true
define i1 @maxnum_oge_large_max_constant(float %x) {
; CHECK-LABEL: @maxnum_oge_large_max_constant(
; CHECK-NEXT: ret i1 true
;
%max = call float @llvm.maxnum.f32(float %x, float 1.5)
%cmp = fcmp oge float %max, 1.0
ret i1 %cmp
}
; max(x, 1.5) != 1.0 --> true
define i1 @maxnum_one_large_max_constant(float %x) {
; CHECK-LABEL: @maxnum_one_large_max_constant(
; CHECK-NEXT: ret i1 true
;
%max = call float @llvm.maxnum.f32(float %x, float 1.5)
%cmp = fcmp one float %max, 1.0
ret i1 %cmp
}
; max(x, 1.5) > 1.0 --> true
define i1 @maxnum_ugt_large_max_constant(float %x) {
; CHECK-LABEL: @maxnum_ugt_large_max_constant(
; CHECK-NEXT: ret i1 true
;
%max = call float @llvm.maxnum.f32(float %x, float 1.5)
%cmp = fcmp ugt float %max, 1.0
ret i1 %cmp
}
; max(x, 1.5) >= 1.0 --> true
define i1 @maxnum_uge_large_max_constant(float %x) {
; CHECK-LABEL: @maxnum_uge_large_max_constant(
; CHECK-NEXT: ret i1 true
;
%max = call float @llvm.maxnum.f32(float %x, float 1.5)
%cmp = fcmp uge float %max, 1.0
ret i1 %cmp
}
; max(x, 1.5) != 1.0 --> true
define i1 @maxnum_une_large_max_constant(float %x) {
; CHECK-LABEL: @maxnum_une_large_max_constant(
; CHECK-NEXT: ret i1 true
;
%max = call float @llvm.maxnum.f32(float %x, float 1.5)
%cmp = fcmp une float %max, 1.0
ret i1 %cmp
}
; Negative test:
; max(x, 1.0) != 1.0 --> ?
define i1 @maxnum_une_equal_max_constant(float %x) {
; CHECK-LABEL: @maxnum_une_equal_max_constant(
; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float 1.000000e+00)
; CHECK-NEXT: [[CMP:%.*]] = fcmp une float [[MAX]], 1.000000e+00
; CHECK-NEXT: ret i1 [[CMP]]
;
%max = call float @llvm.maxnum.f32(float %x, float 1.0)
%cmp = fcmp une float %max, 1.0
ret i1 %cmp
}
; Negative test:
; max(x, 0.5) != 1.0 --> ?
define i1 @maxnum_une_small_max_constant(float %x) {
; CHECK-LABEL: @maxnum_une_small_max_constant(
; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float 5.000000e-01)
; CHECK-NEXT: [[CMP:%.*]] = fcmp une float [[MAX]], 1.000000e+00
; CHECK-NEXT: ret i1 [[CMP]]
;
%max = call float @llvm.maxnum.f32(float %x, float 0.5)
%cmp = fcmp une float %max, 1.0
ret i1 %cmp
}
; Partial negative test (the maxnum simplifies):
; max(x, NaN) != 1.0 --> x != 1.0
define i1 @maxnum_une_nan_max_constant(float %x) {
; CHECK-LABEL: @maxnum_une_nan_max_constant(
; CHECK-NEXT: [[CMP:%.*]] = fcmp une float [[X:%.*]], 1.000000e+00
; CHECK-NEXT: ret i1 [[CMP]]
;
%max = call float @llvm.maxnum.f32(float %x, float 0x7FF8000000000000)
%cmp = fcmp une float %max, 1.0
ret i1 %cmp
}
define i1 @known_positive_olt_with_negative_constant(double %a) {
; CHECK-LABEL: @known_positive_olt_with_negative_constant(
; CHECK-NEXT: ret i1 false
;
%call = call double @llvm.fabs.f64(double %a)
%cmp = fcmp olt double %call, -1.0
ret i1 %cmp
}
define <2 x i1> @known_positive_ole_with_negative_constant_splat_vec(<2 x i32> %a) {
; CHECK-LABEL: @known_positive_ole_with_negative_constant_splat_vec(
; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%call = uitofp <2 x i32> %a to <2 x double>
%cmp = fcmp ole <2 x double> %call, <double -2.0, double -2.0>
ret <2 x i1> %cmp
}
define i1 @known_positive_ugt_with_negative_constant(i32 %a) {
; CHECK-LABEL: @known_positive_ugt_with_negative_constant(
; CHECK-NEXT: ret i1 true
;
%call = uitofp i32 %a to float
%cmp = fcmp ugt float %call, -3.0
ret i1 %cmp
}
define <2 x i1> @known_positive_uge_with_negative_constant_splat_vec(<2 x float> %a) {
; CHECK-LABEL: @known_positive_uge_with_negative_constant_splat_vec(
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%call = call <2 x float> @llvm.fabs.v2f32(<2 x float> %a)
%cmp = fcmp uge <2 x float> %call, <float -4.0, float -4.0>
ret <2 x i1> %cmp
}
define i1 @known_positive_oeq_with_negative_constant(half %a) {
; CHECK-LABEL: @known_positive_oeq_with_negative_constant(
; CHECK-NEXT: ret i1 false
;
%call = call half @llvm.fabs.f16(half %a)
%cmp = fcmp oeq half %call, -5.0
ret i1 %cmp
}
define <2 x i1> @known_positive_une_with_negative_constant_splat_vec(<2 x i32> %a) {
; CHECK-LABEL: @known_positive_une_with_negative_constant_splat_vec(
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%call = uitofp <2 x i32> %a to <2 x half>
%cmp = fcmp une <2 x half> %call, <half -6.0, half -6.0>
ret <2 x i1> %cmp
}
define i1 @nonans1(double %in1, double %in2) {
; CHECK-LABEL: @nonans1(
; CHECK-NEXT: ret i1 false
;
%cmp = fcmp nnan uno double %in1, %in2
ret i1 %cmp
}
define i1 @nonans2(double %in1, double %in2) {
; CHECK-LABEL: @nonans2(
; CHECK-NEXT: ret i1 true
;
%cmp = fcmp nnan ord double %in1, %in2
ret i1 %cmp
}
define <2 x i1> @orderedCompareWithNaNVector(<2 x double> %A) {
; CHECK-LABEL: @orderedCompareWithNaNVector(
; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%cmp = fcmp olt <2 x double> %A, <double 0xFFFFFFFFFFFFFFFF, double 0xFFFFFFFFFFFFFFFF>
ret <2 x i1> %cmp
}
define <2 x i1> @orderedCompareWithNaNVector_undef_elt(<2 x double> %A) {
; CHECK-LABEL: @orderedCompareWithNaNVector_undef_elt(
; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%cmp = fcmp olt <2 x double> %A, <double 0xFFFFFFFFFFFFFFFF, double undef>
ret <2 x i1> %cmp
}
define <2 x i1> @unorderedCompareWithNaNVector_undef_elt(<2 x double> %A) {
; CHECK-LABEL: @unorderedCompareWithNaNVector_undef_elt(
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%cmp = fcmp ult <2 x double> %A, <double undef, double 0xFFFFFFFFFFFFFFFF>
ret <2 x i1> %cmp
}