[InstCombine] Signed saturation patterns
[llvm-core.git] / test / Feature / fp-intrinsics.ll
blob616897c3a00232d2fd34b7400bca410f2b87b2aa
1 ; RUN: opt -O3 -S < %s | FileCheck %s
3 ; Test to verify that constants aren't folded when the rounding mode is unknown.
4 ; CHECK-LABEL: @f1
5 ; CHECK: call double @llvm.experimental.constrained.fdiv.f64
6 define double @f1() #0 {
7 entry:
8   %div = call double @llvm.experimental.constrained.fdiv.f64(
9                                                double 1.000000e+00,
10                                                double 1.000000e+01,
11                                                metadata !"round.dynamic",
12                                                metadata !"fpexcept.strict") #0
13   ret double %div
16 ; Verify that 'a - 0' isn't simplified to 'a' when the rounding mode is unknown.
18 ; double f2(double a) {
19 ;   // Because the result of '0 - 0' is negative zero if rounding mode is
20 ;   // downward, this shouldn't be simplified.
21 ;   return a - 0.0;
22 ; }
24 ; CHECK-LABEL: @f2
25 ; CHECK: call double @llvm.experimental.constrained.fsub.f64
26 define double @f2(double %a) #0 {
27 entry:
28   %div = call double @llvm.experimental.constrained.fsub.f64(
29                                                double %a, double 0.000000e+00,
30                                                metadata !"round.dynamic",
31                                                metadata !"fpexcept.strict") #0
32   ret double %div
35 ; Verify that '-((-a)*b)' isn't simplified to 'a*b' when the rounding mode is
36 ; unknown.
38 ; double f3(double a, double b) {
39 ;   // Because the intermediate value involved in this calculation may require
40 ;   // rounding, this shouldn't be simplified.
41 ;   return -((-a)*b);
42 ; }
44 ; CHECK-LABEL: @f3
45 ; CHECK: call double @llvm.experimental.constrained.fsub.f64
46 ; CHECK: call double @llvm.experimental.constrained.fmul.f64
47 ; CHECK: call double @llvm.experimental.constrained.fsub.f64
48 define double @f3(double %a, double %b) #0 {
49 entry:
50   %sub = call double @llvm.experimental.constrained.fsub.f64(
51                                                double -0.000000e+00, double %a,
52                                                metadata !"round.dynamic",
53                                                metadata !"fpexcept.strict") #0
54   %mul = call double @llvm.experimental.constrained.fmul.f64(
55                                                double %sub, double %b,
56                                                metadata !"round.dynamic",
57                                                metadata !"fpexcept.strict") #0
58   %ret = call double @llvm.experimental.constrained.fsub.f64(
59                                                double -0.000000e+00,
60                                                double %mul,
61                                                metadata !"round.dynamic",
62                                                metadata !"fpexcept.strict") #0
63   ret double %ret
66 ; Verify that FP operations are not performed speculatively when FP exceptions
67 ; are not being ignored.
69 ; double f4(int n, double a) {
70 ;   // Because a + 1 may overflow, this should not be simplified.
71 ;   if (n > 0)
72 ;     return a + 1.0;
73 ;   return a;
74 ; }
77 ; CHECK-LABEL: @f4
78 ; CHECK-NOT: select
79 ; CHECK: br i1 %cmp
80 define double @f4(i32 %n, double %a) #0 {
81 entry:
82   %cmp = icmp sgt i32 %n, 0
83   br i1 %cmp, label %if.then, label %if.end
85 if.then:
86   %add = call double @llvm.experimental.constrained.fadd.f64(
87                                                double 1.000000e+00, double %a,
88                                                metadata !"round.dynamic",
89                                                metadata !"fpexcept.strict") #0
90   br label %if.end
92 if.end:
93   %a.0 = phi double [%add, %if.then], [ %a, %entry ]
94   ret double %a.0
97 ; Verify that sqrt(42.0) isn't simplified when the rounding mode is unknown.
98 ; CHECK-LABEL: f5
99 ; CHECK: call double @llvm.experimental.constrained.sqrt
100 define double @f5() #0 {
101 entry:
102   %result = call double @llvm.experimental.constrained.sqrt.f64(double 42.0,
103                                                metadata !"round.dynamic",
104                                                metadata !"fpexcept.strict") #0
105   ret double %result
108 ; Verify that pow(42.1, 3.0) isn't simplified when the rounding mode is unknown.
109 ; CHECK-LABEL: f6
110 ; CHECK: call double @llvm.experimental.constrained.pow
111 define double @f6() #0 {
112 entry:
113   %result = call double @llvm.experimental.constrained.pow.f64(double 42.1,
114                                                double 3.0,
115                                                metadata !"round.dynamic",
116                                                metadata !"fpexcept.strict") #0
117   ret double %result
120 ; Verify that powi(42.1, 3) isn't simplified when the rounding mode is unknown.
121 ; CHECK-LABEL: f7
122 ; CHECK: call double @llvm.experimental.constrained.powi
123 define double @f7() #0 {
124 entry:
125   %result = call double @llvm.experimental.constrained.powi.f64(double 42.1,
126                                                i32 3,
127                                                metadata !"round.dynamic",
128                                                metadata !"fpexcept.strict") #0
129   ret double %result
132 ; Verify that sin(42.0) isn't simplified when the rounding mode is unknown.
133 ; CHECK-LABEL: f8
134 ; CHECK: call double @llvm.experimental.constrained.sin
135 define double @f8() #0 {
136 entry:
137   %result = call double @llvm.experimental.constrained.sin.f64(double 42.0,
138                                                metadata !"round.dynamic",
139                                                metadata !"fpexcept.strict") #0
140   ret double %result
143 ; Verify that cos(42.0) isn't simplified when the rounding mode is unknown.
144 ; CHECK-LABEL: f9
145 ; CHECK: call double @llvm.experimental.constrained.cos
146 define double @f9() #0 {
147 entry:
148   %result = call double @llvm.experimental.constrained.cos.f64(double 42.0,
149                                                metadata !"round.dynamic",
150                                                metadata !"fpexcept.strict") #0
151   ret double %result
154 ; Verify that exp(42.0) isn't simplified when the rounding mode is unknown.
155 ; CHECK-LABEL: f10
156 ; CHECK: call double @llvm.experimental.constrained.exp
157 define double @f10() #0 {
158 entry:
159   %result = call double @llvm.experimental.constrained.exp.f64(double 42.0,
160                                                metadata !"round.dynamic",
161                                                metadata !"fpexcept.strict") #0
162   ret double %result
165 ; Verify that exp2(42.1) isn't simplified when the rounding mode is unknown.
166 ; CHECK-LABEL: f11
167 ; CHECK: call double @llvm.experimental.constrained.exp2
168 define double @f11() #0 {
169 entry:
170   %result = call double @llvm.experimental.constrained.exp2.f64(double 42.1,
171                                                metadata !"round.dynamic",
172                                                metadata !"fpexcept.strict") #0
173   ret double %result
176 ; Verify that log(42.0) isn't simplified when the rounding mode is unknown.
177 ; CHECK-LABEL: f12
178 ; CHECK: call double @llvm.experimental.constrained.log
179 define double @f12() #0 {
180 entry:
181   %result = call double @llvm.experimental.constrained.log.f64(double 42.0,
182                                                metadata !"round.dynamic",
183                                                metadata !"fpexcept.strict") #0
184   ret double %result
187 ; Verify that log10(42.0) isn't simplified when the rounding mode is unknown.
188 ; CHECK-LABEL: f13
189 ; CHECK: call double @llvm.experimental.constrained.log10
190 define double @f13() #0 {
191 entry:
192   %result = call double @llvm.experimental.constrained.log10.f64(double 42.0,
193                                                metadata !"round.dynamic",
194                                                metadata !"fpexcept.strict") #0
195   ret double %result
198 ; Verify that log2(42.0) isn't simplified when the rounding mode is unknown.
199 ; CHECK-LABEL: f14
200 ; CHECK: call double @llvm.experimental.constrained.log2
201 define double @f14() #0 {
202 entry:
203   %result = call double @llvm.experimental.constrained.log2.f64(double 42.0,
204                                                metadata !"round.dynamic",
205                                                metadata !"fpexcept.strict") #0
206   ret double %result
209 ; Verify that rint(42.1) isn't simplified when the rounding mode is unknown.
210 ; CHECK-LABEL: f15
211 ; CHECK: call double @llvm.experimental.constrained.rint
212 define double @f15() #0 {
213 entry:
214   %result = call double @llvm.experimental.constrained.rint.f64(double 42.1,
215                                                metadata !"round.dynamic",
216                                                metadata !"fpexcept.strict") #0
217   ret double %result
220 ; Verify that nearbyint(42.1) isn't simplified when the rounding mode is
221 ; unknown.
222 ; CHECK-LABEL: f16
223 ; CHECK: call double @llvm.experimental.constrained.nearbyint
224 define double @f16() #0 {
225 entry:
226   %result = call double @llvm.experimental.constrained.nearbyint.f64(
227                                                double 42.1,
228                                                metadata !"round.dynamic",
229                                                metadata !"fpexcept.strict") #0
230   ret double %result
233 ; Verify that fma(42.1) isn't simplified when the rounding mode is
234 ; unknown.
235 ; CHECK-LABEL: f17
236 ; CHECK: call double @llvm.experimental.constrained.fma
237 define double @f17() #0 {
238 entry:
239   %result = call double @llvm.experimental.constrained.fma.f64(double 42.1, double 42.1, double 42.1,
240                                                metadata !"round.dynamic",
241                                                metadata !"fpexcept.strict") #0
242   ret double %result
245 ; Verify that fptoui(42.1) isn't simplified when the rounding mode is
246 ; unknown.
247 ; CHECK-LABEL: f18
248 ; CHECK: call zeroext i32 @llvm.experimental.constrained.fptoui
249 define zeroext i32 @f18() #0 {
250 entry:
251   %result = call zeroext i32 @llvm.experimental.constrained.fptoui.i32.f64(
252                                                double 42.1,
253                                                metadata !"fpexcept.strict") #0
254   ret i32 %result
257 ; Verify that fptosi(42.1) isn't simplified when the rounding mode is
258 ; unknown.
259 ; CHECK-LABEL: f19
260 ; CHECK: call i32 @llvm.experimental.constrained.fptosi
261 define i32 @f19() #0 {
262 entry:
263   %result = call i32 @llvm.experimental.constrained.fptosi.i32.f64(double 42.1,
264                                                metadata !"fpexcept.strict") #0
265   ret i32 %result
268 ; Verify that fptrunc(42.1) isn't simplified when the rounding mode is
269 ; unknown.
270 ; CHECK-LABEL: f20
271 ; CHECK: call float @llvm.experimental.constrained.fptrunc
272 define float @f20() #0 {
273 entry:
274   %result = call float @llvm.experimental.constrained.fptrunc.f32.f64(
275                                                double 42.1,
276                                                metadata !"round.dynamic",
277                                                metadata !"fpexcept.strict") #0
278   ret float %result
281 ; Verify that fpext(42.1) isn't simplified when the rounding mode is
282 ; unknown.
283 ; CHECK-LABEL: f21
284 ; CHECK: call double @llvm.experimental.constrained.fpext
285 define double @f21() #0 {
286 entry:
287   %result = call double @llvm.experimental.constrained.fpext.f64.f32(float 42.0,
288                                                metadata !"fpexcept.strict") #0
289   ret double %result
292 ; Verify that lrint(42.1) isn't simplified when the rounding mode is unknown.
293 ; CHECK-LABEL: f22
294 ; CHECK: call i32 @llvm.experimental.constrained.lrint
295 define i32 @f22() #0 {
296 entry:
297   %result = call i32 @llvm.experimental.constrained.lrint.i32.f64(double 42.1,
298                                                metadata !"round.dynamic",
299                                                metadata !"fpexcept.strict") #0
300   ret i32 %result
303 ; Verify that lrintf(42.0) isn't simplified when the rounding mode is unknown.
304 ; CHECK-LABEL: f23
305 ; CHECK: call i32 @llvm.experimental.constrained.lrint
306 define i32 @f23() #0 {
307 entry:
308   %result = call i32 @llvm.experimental.constrained.lrint.i32.f32(float 42.0,
309                                                metadata !"round.dynamic",
310                                                metadata !"fpexcept.strict") #0
311   ret i32 %result
314 ; Verify that llrint(42.1) isn't simplified when the rounding mode is unknown.
315 ; CHECK-LABEL: f24
316 ; CHECK: call i64 @llvm.experimental.constrained.llrint
317 define i64 @f24() #0 {
318 entry:
319   %result = call i64 @llvm.experimental.constrained.llrint.i64.f64(double 42.1,
320                                                metadata !"round.dynamic",
321                                                metadata !"fpexcept.strict") #0
322   ret i64 %result
325 ; Verify that llrint(42.0) isn't simplified when the rounding mode is unknown.
326 ; CHECK-LABEL: f25
327 ; CHECK: call i64 @llvm.experimental.constrained.llrint
328 define i64 @f25() #0 {
329 entry:
330   %result = call i64 @llvm.experimental.constrained.llrint.i64.f32(float 42.0,
331                                                metadata !"round.dynamic",
332                                                metadata !"fpexcept.strict") #0
333   ret i64 %result
336 ; Verify that lround(42.1) isn't simplified when the rounding mode is unknown.
337 ; CHECK-LABEL: f26
338 ; CHECK: call i32 @llvm.experimental.constrained.lround
339 define i32 @f26() #0 {
340 entry:
341   %result = call i32 @llvm.experimental.constrained.lround.i32.f64(double 42.1,
342                                                metadata !"fpexcept.strict") #0
343   ret i32 %result
346 ; Verify that lround(42.0) isn't simplified when the rounding mode is unknown.
347 ; CHECK-LABEL: f27
348 ; CHECK: call i32 @llvm.experimental.constrained.lround
349 define i32 @f27() #0 {
350 entry:
351   %result = call i32 @llvm.experimental.constrained.lround.i32.f32(float 42.0,
352                                                metadata !"fpexcept.strict") #0
353   ret i32 %result
356 ; Verify that llround(42.1) isn't simplified when the rounding mode is unknown.
357 ; CHECK-LABEL: f28
358 ; CHECK: call i64 @llvm.experimental.constrained.llround
359 define i64 @f28() #0 {
360 entry:
361   %result = call i64 @llvm.experimental.constrained.llround.i64.f64(double 42.1,
362                                                metadata !"fpexcept.strict") #0
363   ret i64 %result
366 ; Verify that llround(42.0) isn't simplified when the rounding mode is unknown.
367 ; CHECK-LABEL: f29
368 ; CHECK: call i64 @llvm.experimental.constrained.llround
369 define i64 @f29() #0 {
370 entry:
371   %result = call i64 @llvm.experimental.constrained.llround.i64.f32(float 42.0,
372                                                metadata !"fpexcept.strict") #0
373   ret i64 %result
376 attributes #0 = { strictfp }
378 @llvm.fp.env = thread_local global i8 zeroinitializer, section "llvm.metadata"
379 declare double @llvm.experimental.constrained.fdiv.f64(double, double, metadata, metadata)
380 declare double @llvm.experimental.constrained.fmul.f64(double, double, metadata, metadata)
381 declare double @llvm.experimental.constrained.fadd.f64(double, double, metadata, metadata)
382 declare double @llvm.experimental.constrained.fsub.f64(double, double, metadata, metadata)
383 declare double @llvm.experimental.constrained.sqrt.f64(double, metadata, metadata)
384 declare double @llvm.experimental.constrained.pow.f64(double, double, metadata, metadata)
385 declare double @llvm.experimental.constrained.powi.f64(double, i32, metadata, metadata)
386 declare double @llvm.experimental.constrained.sin.f64(double, metadata, metadata)
387 declare double @llvm.experimental.constrained.cos.f64(double, metadata, metadata)
388 declare double @llvm.experimental.constrained.exp.f64(double, metadata, metadata)
389 declare double @llvm.experimental.constrained.exp2.f64(double, metadata, metadata)
390 declare double @llvm.experimental.constrained.log.f64(double, metadata, metadata)
391 declare double @llvm.experimental.constrained.log10.f64(double, metadata, metadata)
392 declare double @llvm.experimental.constrained.log2.f64(double, metadata, metadata)
393 declare double @llvm.experimental.constrained.rint.f64(double, metadata, metadata)
394 declare double @llvm.experimental.constrained.nearbyint.f64(double, metadata, metadata)
395 declare double @llvm.experimental.constrained.fma.f64(double, double, double, metadata, metadata)
396 declare i32 @llvm.experimental.constrained.fptosi.i32.f64(double, metadata)
397 declare i32 @llvm.experimental.constrained.fptoui.i32.f64(double, metadata)
398 declare float @llvm.experimental.constrained.fptrunc.f32.f64(double, metadata, metadata)
399 declare double @llvm.experimental.constrained.fpext.f64.f32(float, metadata)
400 declare i32 @llvm.experimental.constrained.lrint.i32.f64(double, metadata, metadata)
401 declare i32 @llvm.experimental.constrained.lrint.i32.f32(float, metadata, metadata)
402 declare i64 @llvm.experimental.constrained.llrint.i64.f64(double, metadata, metadata)
403 declare i64 @llvm.experimental.constrained.llrint.i64.f32(float, metadata, metadata)
404 declare i32 @llvm.experimental.constrained.lround.i32.f64(double, metadata)
405 declare i32 @llvm.experimental.constrained.lround.i32.f32(float, metadata)
406 declare i64 @llvm.experimental.constrained.llround.i64.f64(double, metadata)
407 declare i64 @llvm.experimental.constrained.llround.i64.f32(float, metadata)