llvm.org GIT mirror llvm / 6b617a7
Constant-fold certain comparisons with infinity and negative infinity. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96777 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
2 changed file(s) with 181 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
282282 // True if unordered.
283283 return ConstantInt::getTrue(CFP->getContext());
284284 }
285 // Check whether the constant is an infinity.
286 if (CFP->getValueAPF().isInfinity()) {
287 if (CFP->getValueAPF().isNegative()) {
288 switch (Pred) {
289 case FCmpInst::FCMP_OLT:
290 // No value is ordered and less than negative infinity.
291 return ConstantInt::getFalse(CFP->getContext());
292 case FCmpInst::FCMP_UGE:
293 // All values are unordered with or at least negative infinity.
294 return ConstantInt::getTrue(CFP->getContext());
295 default:
296 break;
297 }
298 } else {
299 switch (Pred) {
300 case FCmpInst::FCMP_OGT:
301 // No value is ordered and greater than infinity.
302 return ConstantInt::getFalse(CFP->getContext());
303 case FCmpInst::FCMP_ULE:
304 // All values are unordered with and at most infinity.
305 return ConstantInt::getTrue(CFP->getContext());
306 default:
307 break;
308 }
309 }
310 }
285311 }
286312 }
287313
0 ; RUN: opt < %s -instcombine -S | FileCheck %s
1
2 ; Infinity
3
4 ; CHECK: inf0
5 ; CHECK: ret i1 false
6 define i1 @inf0(double %arg) nounwind readnone {
7 %tmp = fcmp ogt double %arg, 0x7FF0000000000000
8 ret i1 %tmp
9 }
10
11 ; CHECK: inf1
12 ; CHECK: ret i1 true
13 define i1 @inf1(double %arg) nounwind readnone {
14 %tmp = fcmp ule double %arg, 0x7FF0000000000000
15 ret i1 %tmp
16 }
17
18 ; Negative infinity
19
20 ; CHECK: ninf0
21 ; CHECK: ret i1 false
22 define i1 @ninf0(double %arg) nounwind readnone {
23 %tmp = fcmp olt double %arg, 0xFFF0000000000000
24 ret i1 %tmp
25 }
26
27 ; CHECK: ninf1
28 ; CHECK: ret i1 true
29 define i1 @ninf1(double %arg) nounwind readnone {
30 %tmp = fcmp uge double %arg, 0xFFF0000000000000
31 ret i1 %tmp
32 }
33
34 ; NaNs
35
36 ; CHECK: nan0
37 ; CHECK: ret i1 false
38 define i1 @nan0(double %arg) nounwind readnone {
39 %tmp = fcmp ord double %arg, 0x7FF00000FFFFFFFF
40 ret i1 %tmp
41 }
42
43 ; CHECK: nan1
44 ; CHECK: ret i1 false
45 define i1 @nan1(double %arg) nounwind readnone {
46 %tmp = fcmp oeq double %arg, 0x7FF00000FFFFFFFF
47 ret i1 %tmp
48 }
49
50 ; CHECK: nan2
51 ; CHECK: ret i1 false
52 define i1 @nan2(double %arg) nounwind readnone {
53 %tmp = fcmp olt double %arg, 0x7FF00000FFFFFFFF
54 ret i1 %tmp
55 }
56
57 ; CHECK: nan3
58 ; CHECK: ret i1 true
59 define i1 @nan3(double %arg) nounwind readnone {
60 %tmp = fcmp uno double %arg, 0x7FF00000FFFFFFFF
61 ret i1 %tmp
62 }
63
64 ; CHECK: nan4
65 ; CHECK: ret i1 true
66 define i1 @nan4(double %arg) nounwind readnone {
67 %tmp = fcmp une double %arg, 0x7FF00000FFFFFFFF
68 ret i1 %tmp
69 }
70
71 ; CHECK: nan5
72 ; CHECK: ret i1 true
73 define i1 @nan5(double %arg) nounwind readnone {
74 %tmp = fcmp ult double %arg, 0x7FF00000FFFFFFFF
75 ret i1 %tmp
76 }
77
78 ; Negative NaN.
79
80 ; CHECK: nnan0
81 ; CHECK: ret i1 false
82 define i1 @nnan0(double %arg) nounwind readnone {
83 %tmp = fcmp ord double %arg, 0xFFF00000FFFFFFFF
84 ret i1 %tmp
85 }
86
87 ; CHECK: nnan1
88 ; CHECK: ret i1 false
89 define i1 @nnan1(double %arg) nounwind readnone {
90 %tmp = fcmp oeq double %arg, 0xFFF00000FFFFFFFF
91 ret i1 %tmp
92 }
93
94 ; CHECK: nnan2
95 ; CHECK: ret i1 false
96 define i1 @nnan2(double %arg) nounwind readnone {
97 %tmp = fcmp olt double %arg, 0xFFF00000FFFFFFFF
98 ret i1 %tmp
99 }
100
101 ; CHECK: nnan3
102 ; CHECK: ret i1 true
103 define i1 @nnan3(double %arg) nounwind readnone {
104 %tmp = fcmp uno double %arg, 0xFFF00000FFFFFFFF
105 ret i1 %tmp
106 }
107
108 ; CHECK: nnan4
109 ; CHECK: ret i1 true
110 define i1 @nnan4(double %arg) nounwind readnone {
111 %tmp = fcmp une double %arg, 0xFFF00000FFFFFFFF
112 ret i1 %tmp
113 }
114
115 ; CHECK: nnan5
116 ; CHECK: ret i1 true
117 define i1 @nnan5(double %arg) nounwind readnone {
118 %tmp = fcmp ult double %arg, 0xFFF00000FFFFFFFF
119 ret i1 %tmp
120 }
121
122 ; Negative zero.
123
124 ; CHECK: nzero0
125 ; CHECK: ret i1 true
126 define i1 @nzero0() {
127 %tmp = fcmp oeq double 0.0, -0.0
128 ret i1 %tmp
129 }
130
131 ; CHECK: nzero1
132 ; CHECK: ret i1 false
133 define i1 @nzero1() {
134 %tmp = fcmp ogt double 0.0, -0.0
135 ret i1 %tmp
136 }
137
138 ; Misc.
139
140 ; CHECK: misc0
141 ; CHECK: %tmp = fcmp ord double %arg, 0.000000e+00
142 ; CHECK: ret i1 %tmp
143 define i1 @misc0(double %arg) {
144 %tmp = fcmp oeq double %arg, %arg
145 ret i1 %tmp
146 }
147
148 ; CHECK: misc1
149 ; CHECK: ret i1 false
150 define i1 @misc1(double %arg) {
151 %tmp = fcmp one double %arg, %arg
152 ret i1 %tmp
153 }
154