Merging r258325:
[oota-llvm.git] / test / Transforms / InstSimplify / floating-point-compare.ll
1 ; RUN: opt < %s -instsimplify -S | FileCheck %s
2
3 ; These tests choose arbitrarily between float and double,
4 ; and between uge and olt, to give reasonble coverage 
5 ; without combinatorial explosion.
6
7 declare float @llvm.fabs.f32(float)
8 declare float @llvm.sqrt.f32(float)
9 declare double @llvm.powi.f64(double,i32)
10 declare float @llvm.exp.f32(float)
11 declare float @llvm.minnum.f32(float, float)
12 declare float @llvm.maxnum.f32(float, float)
13 declare double @llvm.exp2.f64(double)
14 declare float @llvm.fma.f32(float,float,float)
15
16 declare void @expect_equal(i1,i1)
17
18 ; CHECK-LABEL: @orderedLessZeroTree(
19 define i1 @orderedLessZeroTree(float,float,float,float) {
20   %square = fmul float %0, %0
21   %abs = call float @llvm.fabs.f32(float %1)
22   %sqrt = call float @llvm.sqrt.f32(float %2)
23   %fma = call float @llvm.fma.f32(float %3, float %3, float %sqrt)
24   %div = fdiv float %square, %abs
25   %rem = frem float %sqrt, %fma
26   %add = fadd float %div, %rem
27   %uge = fcmp uge float %add, 0.000000e+00
28 ; CHECK: ret i1 true
29   ret i1 %uge
30 }
31
32 ; CHECK-LABEL: @orderedLessZeroExpExt(
33 define i1 @orderedLessZeroExpExt(float) {
34   %a = call float @llvm.exp.f32(float %0)
35   %b = fpext float %a to double
36   %uge = fcmp uge double %b, 0.000000e+00
37 ; CHECK: ret i1 true
38   ret i1 %uge
39 }
40
41 ; CHECK-LABEL: @orderedLessZeroExp2Trunc(
42 define i1 @orderedLessZeroExp2Trunc(double) {
43   %a = call double @llvm.exp2.f64(double %0)
44   %b = fptrunc double %a to float
45   %olt = fcmp olt float %b, 0.000000e+00
46 ; CHECK: ret i1 false
47   ret i1 %olt
48 }
49
50 ; CHECK-LABEL: @orderedLessZeroPowi(
51 define i1 @orderedLessZeroPowi(double,double) {
52   ; Even constant exponent
53   %a = call double @llvm.powi.f64(double %0, i32 2)
54   %square = fmul double %1, %1
55   ; Odd constant exponent with provably non-negative base
56   %b = call double @llvm.powi.f64(double %square, i32 3)
57   %c = fadd double %a, %b
58   %olt = fcmp olt double %b, 0.000000e+00
59 ; CHECK: ret i1 false
60   ret i1 %olt
61 }
62
63 ; CHECK-LABEL: @orderedLessZeroUIToFP(
64 define i1 @orderedLessZeroUIToFP(i32) {
65   %a = uitofp i32 %0 to float
66   %uge = fcmp uge float %a, 0.000000e+00
67 ; CHECK: ret i1 true
68   ret i1 %uge
69 }
70
71 ; CHECK-LABEL: @orderedLessZeroSelect(
72 define i1 @orderedLessZeroSelect(float, float) {
73   %a = call float @llvm.exp.f32(float %0)
74   %b = call float @llvm.fabs.f32(float %1)
75   %c = fcmp olt float %0, %1
76   %d = select i1 %c, float %a, float %b
77   %e = fadd float %d, 1.0
78   %uge = fcmp uge float %e, 0.000000e+00
79 ; CHECK: ret i1 true
80   ret i1 %uge
81 }
82
83 ; CHECK-LABEL: @orderedLessZeroMinNum(
84 define i1 @orderedLessZeroMinNum(float, float) {
85   %a = call float @llvm.exp.f32(float %0)
86   %b = call float @llvm.fabs.f32(float %1)
87   %c = call float @llvm.minnum.f32(float %a, float %b)
88   %uge = fcmp uge float %c, 0.000000e+00
89 ; CHECK: ret i1 true
90   ret i1 %uge
91 }
92
93 ; CHECK-LABEL: @orderedLessZeroMaxNum(
94 define i1 @orderedLessZeroMaxNum(float, float) {
95   %a = call float @llvm.exp.f32(float %0)
96   %b = call float @llvm.maxnum.f32(float %a, float %1)
97   %uge = fcmp uge float %b, 0.000000e+00
98 ; CHECK: ret i1 true
99   ret i1 %uge
100 }
101
102 define i1 @nonans1(double %in1, double %in2) {
103   %cmp = fcmp nnan uno double %in1, %in2
104   ret i1 %cmp
105
106 ; CHECK-LABEL: @nonans1
107 ; CHECK-NEXT: ret i1 false
108 }
109
110 define i1 @nonans2(double %in1, double %in2) {
111   %cmp = fcmp nnan ord double %in1, %in2
112   ret i1 %cmp
113
114 ; CHECK-LABEL: @nonans2
115 ; CHECK-NEXT: ret i1 true
116 }