blob: b148d9961d33870b70840ae0128e09892dd5f61f [file] [log] [blame]
Elena Demikhovsky45f04482015-01-28 08:03:58 +00001; 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
7declare float @llvm.fabs.f32(float)
8declare float @llvm.sqrt.f32(float)
9declare double @llvm.powi.f64(double,i32)
10declare float @llvm.exp.f32(float)
Fiona Glaserdb7824f2016-01-12 23:37:30 +000011declare float @llvm.minnum.f32(float, float)
12declare float @llvm.maxnum.f32(float, float)
Elena Demikhovsky45f04482015-01-28 08:03:58 +000013declare double @llvm.exp2.f64(double)
14declare float @llvm.fma.f32(float,float,float)
15
16declare void @expect_equal(i1,i1)
17
18; CHECK-LABEL: @orderedLessZeroTree(
19define 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(
33define 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(
42define 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(
51define 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
Fiona Glaserdb7824f2016-01-12 23:37:30 +000063; CHECK-LABEL: @orderedLessZeroUIToFP(
64define 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(
72define 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(
84define 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(
94define 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
Benjamin Kramerf4ebfa32015-07-10 14:02:02 +0000102define 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
110define 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}