AMDGPU: Use isWave[32|64] instead of comparing size value (#117411)
[llvm-project.git] / llvm / test / Feature / fp-intrinsics.ll
blobada22c39abc9e719a2d283105bb6b65f97f154fa
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 tan(42.0) isn't simplified when the rounding mode is unknown.
155 ; CHECK-LABEL: ftan
156 ; CHECK: call double @llvm.experimental.constrained.tan
157 define double @ftan() #0 {
158 entry:
159   %result = call double @llvm.experimental.constrained.tan.f64(double 42.0,
160                                                metadata !"round.dynamic",
161                                                metadata !"fpexcept.strict") #0
162   ret double %result
165 ; Verify that acos(42.0) isn't simplified when the rounding mode is unknown.
166 ; CHECK-LABEL: facos
167 ; CHECK: call double @llvm.experimental.constrained.acos
168 define double @facos() #0 {
169 entry:
170   %result = call double @llvm.experimental.constrained.acos.f64(double 42.0,
171                                                metadata !"round.dynamic",
172                                                metadata !"fpexcept.strict") #0
173   ret double %result
176 ; Verify that asin(42.0) isn't simplified when the rounding mode is unknown.
177 ; CHECK-LABEL: fasin
178 ; CHECK: call double @llvm.experimental.constrained.asin
179 define double @fasin() #0 {
180 entry:
181   %result = call double @llvm.experimental.constrained.asin.f64(double 42.0,
182                                                metadata !"round.dynamic",
183                                                metadata !"fpexcept.strict") #0
184   ret double %result
187 ; Verify that atan(42.0, 23.0) isn't simplified when the rounding mode is unknown.
188 ; CHECK-LABEL: fatan
189 ; CHECK: call double @llvm.experimental.constrained.atan
190 define double @fatan() #0 {
191 entry:
192   %result = call double @llvm.experimental.constrained.atan.f64(double 42.0,
193                                                metadata !"round.dynamic",
194                                                metadata !"fpexcept.strict") #0
195   ret double %result
198 ; Verify that atan2(42.0) isn't simplified when the rounding mode is unknown.
199 ; CHECK-LABEL: fatan2
200 ; CHECK: call double @llvm.experimental.constrained.atan2
201 define double @fatan2() #0 {
202 entry:
203   %result = call double @llvm.experimental.constrained.atan2.f64(
204                                               double 42.0,
205                                               double 23.0,
206                                                metadata !"round.dynamic",
207                                                metadata !"fpexcept.strict") #0
208   ret double %result
211 ; Verify that cosh(42.0) isn't simplified when the rounding mode is unknown.
212 ; CHECK-LABEL: fcosh
213 ; CHECK: call double @llvm.experimental.constrained.cosh
214 define double @fcosh() #0 {
215 entry:
216   %result = call double @llvm.experimental.constrained.cosh.f64(double 42.0,
217                                                metadata !"round.dynamic",
218                                                metadata !"fpexcept.strict") #0
219   ret double %result
222 ; Verify that sinh(42.0) isn't simplified when the rounding mode is unknown.
223 ; CHECK-LABEL: fsinh
224 ; CHECK: call double @llvm.experimental.constrained.sinh
225 define double @fsinh() #0 {
226 entry:
227   %result = call double @llvm.experimental.constrained.sinh.f64(double 42.0,
228                                                metadata !"round.dynamic",
229                                                metadata !"fpexcept.strict") #0
230   ret double %result
233 ; Verify that tanh(42.0) isn't simplified when the rounding mode is unknown.
234 ; CHECK-LABEL: ftanh
235 ; CHECK: call double @llvm.experimental.constrained.tanh
236 define double @ftanh() #0 {
237 entry:
238   %result = call double @llvm.experimental.constrained.tanh.f64(double 42.0,
239                                                metadata !"round.dynamic",
240                                                metadata !"fpexcept.strict") #0
241   ret double %result
244 ; Verify that exp(42.0) isn't simplified when the rounding mode is unknown.
245 ; CHECK-LABEL: f10
246 ; CHECK: call double @llvm.experimental.constrained.exp
247 define double @f10() #0 {
248 entry:
249   %result = call double @llvm.experimental.constrained.exp.f64(double 42.0,
250                                                metadata !"round.dynamic",
251                                                metadata !"fpexcept.strict") #0
252   ret double %result
255 ; Verify that exp2(42.1) isn't simplified when the rounding mode is unknown.
256 ; CHECK-LABEL: f11
257 ; CHECK: call double @llvm.experimental.constrained.exp2
258 define double @f11() #0 {
259 entry:
260   %result = call double @llvm.experimental.constrained.exp2.f64(double 42.1,
261                                                metadata !"round.dynamic",
262                                                metadata !"fpexcept.strict") #0
263   ret double %result
266 ; Verify that log(42.0) isn't simplified when the rounding mode is unknown.
267 ; CHECK-LABEL: f12
268 ; CHECK: call double @llvm.experimental.constrained.log
269 define double @f12() #0 {
270 entry:
271   %result = call double @llvm.experimental.constrained.log.f64(double 42.0,
272                                                metadata !"round.dynamic",
273                                                metadata !"fpexcept.strict") #0
274   ret double %result
277 ; Verify that log10(42.0) isn't simplified when the rounding mode is unknown.
278 ; CHECK-LABEL: f13
279 ; CHECK: call double @llvm.experimental.constrained.log10
280 define double @f13() #0 {
281 entry:
282   %result = call double @llvm.experimental.constrained.log10.f64(double 42.0,
283                                                metadata !"round.dynamic",
284                                                metadata !"fpexcept.strict") #0
285   ret double %result
288 ; Verify that log2(42.0) isn't simplified when the rounding mode is unknown.
289 ; CHECK-LABEL: f14
290 ; CHECK: call double @llvm.experimental.constrained.log2
291 define double @f14() #0 {
292 entry:
293   %result = call double @llvm.experimental.constrained.log2.f64(double 42.0,
294                                                metadata !"round.dynamic",
295                                                metadata !"fpexcept.strict") #0
296   ret double %result
299 ; Verify that rint(42.1) isn't simplified when the rounding mode is unknown.
300 ; CHECK-LABEL: f15
301 ; CHECK: call double @llvm.experimental.constrained.rint
302 define double @f15() #0 {
303 entry:
304   %result = call double @llvm.experimental.constrained.rint.f64(double 42.1,
305                                                metadata !"round.dynamic",
306                                                metadata !"fpexcept.strict") #0
307   ret double %result
310 ; Verify that nearbyint(42.1) isn't simplified when the rounding mode is
311 ; unknown.
312 ; CHECK-LABEL: f16
313 ; CHECK: call double @llvm.experimental.constrained.nearbyint
314 define double @f16() #0 {
315 entry:
316   %result = call double @llvm.experimental.constrained.nearbyint.f64(
317                                                double 42.1,
318                                                metadata !"round.dynamic",
319                                                metadata !"fpexcept.strict") #0
320   ret double %result
323 ; Verify that fma(42.1) isn't simplified when the rounding mode is
324 ; unknown.
325 ; CHECK-LABEL: f17
326 ; CHECK: call double @llvm.experimental.constrained.fma
327 define double @f17() #0 {
328 entry:
329   %result = call double @llvm.experimental.constrained.fma.f64(double 42.1, double 42.1, double 42.1,
330                                                metadata !"round.dynamic",
331                                                metadata !"fpexcept.strict") #0
332   ret double %result
335 ; Verify that fptoui(42.1) isn't simplified when the rounding mode is
336 ; unknown.
337 ; CHECK-LABEL: f18
338 ; CHECK: call zeroext i32 @llvm.experimental.constrained.fptoui
339 define zeroext i32 @f18() #0 {
340 entry:
341   %result = call zeroext i32 @llvm.experimental.constrained.fptoui.i32.f64(
342                                                double 42.1,
343                                                metadata !"fpexcept.strict") #0
344   ret i32 %result
347 ; Verify that fptosi(42.1) isn't simplified when the rounding mode is
348 ; unknown.
349 ; CHECK-LABEL: f19
350 ; CHECK: call i32 @llvm.experimental.constrained.fptosi
351 define i32 @f19() #0 {
352 entry:
353   %result = call i32 @llvm.experimental.constrained.fptosi.i32.f64(double 42.1,
354                                                metadata !"fpexcept.strict") #0
355   ret i32 %result
358 ; Verify that fptrunc(42.1) isn't simplified when the rounding mode is
359 ; unknown.
360 ; CHECK-LABEL: f20
361 ; CHECK: call float @llvm.experimental.constrained.fptrunc
362 define float @f20() #0 {
363 entry:
364   %result = call float @llvm.experimental.constrained.fptrunc.f32.f64(
365                                                double 42.1,
366                                                metadata !"round.dynamic",
367                                                metadata !"fpexcept.strict") #0
368   ret float %result
371 ; Verify that fpext(42.1) isn't simplified when the rounding mode is
372 ; unknown.
373 ; CHECK-LABEL: f21
374 ; CHECK: call double @llvm.experimental.constrained.fpext
375 define double @f21() #0 {
376 entry:
377   %result = call double @llvm.experimental.constrained.fpext.f64.f32(float 42.0,
378                                                metadata !"fpexcept.strict") #0
379   ret double %result
382 ; Verify that lrint(42.1) isn't simplified when the rounding mode is unknown.
383 ; CHECK-LABEL: f22
384 ; CHECK: call i32 @llvm.experimental.constrained.lrint
385 define i32 @f22() #0 {
386 entry:
387   %result = call i32 @llvm.experimental.constrained.lrint.i32.f64(double 42.1,
388                                                metadata !"round.dynamic",
389                                                metadata !"fpexcept.strict") #0
390   ret i32 %result
393 ; Verify that lrintf(42.0) isn't simplified when the rounding mode is unknown.
394 ; CHECK-LABEL: f23
395 ; CHECK: call i32 @llvm.experimental.constrained.lrint
396 define i32 @f23() #0 {
397 entry:
398   %result = call i32 @llvm.experimental.constrained.lrint.i32.f32(float 42.0,
399                                                metadata !"round.dynamic",
400                                                metadata !"fpexcept.strict") #0
401   ret i32 %result
404 ; Verify that llrint(42.1) isn't simplified when the rounding mode is unknown.
405 ; CHECK-LABEL: f24
406 ; CHECK: call i64 @llvm.experimental.constrained.llrint
407 define i64 @f24() #0 {
408 entry:
409   %result = call i64 @llvm.experimental.constrained.llrint.i64.f64(double 42.1,
410                                                metadata !"round.dynamic",
411                                                metadata !"fpexcept.strict") #0
412   ret i64 %result
415 ; Verify that llrint(42.0) isn't simplified when the rounding mode is unknown.
416 ; CHECK-LABEL: f25
417 ; CHECK: call i64 @llvm.experimental.constrained.llrint
418 define i64 @f25() #0 {
419 entry:
420   %result = call i64 @llvm.experimental.constrained.llrint.i64.f32(float 42.0,
421                                                metadata !"round.dynamic",
422                                                metadata !"fpexcept.strict") #0
423   ret i64 %result
426 ; Verify that lround(42.1) isn't simplified when the rounding mode is unknown.
427 ; CHECK-LABEL: f26
428 ; CHECK: call i32 @llvm.experimental.constrained.lround
429 define i32 @f26() #0 {
430 entry:
431   %result = call i32 @llvm.experimental.constrained.lround.i32.f64(double 42.1,
432                                                metadata !"fpexcept.strict") #0
433   ret i32 %result
436 ; Verify that lround(42.0) isn't simplified when the rounding mode is unknown.
437 ; CHECK-LABEL: f27
438 ; CHECK: call i32 @llvm.experimental.constrained.lround
439 define i32 @f27() #0 {
440 entry:
441   %result = call i32 @llvm.experimental.constrained.lround.i32.f32(float 42.0,
442                                                metadata !"fpexcept.strict") #0
443   ret i32 %result
446 ; Verify that llround(42.1) isn't simplified when the rounding mode is unknown.
447 ; CHECK-LABEL: f28
448 ; CHECK: call i64 @llvm.experimental.constrained.llround
449 define i64 @f28() #0 {
450 entry:
451   %result = call i64 @llvm.experimental.constrained.llround.i64.f64(double 42.1,
452                                                metadata !"fpexcept.strict") #0
453   ret i64 %result
456 ; Verify that llround(42.0) isn't simplified when the rounding mode is unknown.
457 ; CHECK-LABEL: f29
458 ; CHECK: call i64 @llvm.experimental.constrained.llround
459 define i64 @f29() #0 {
460 entry:
461   %result = call i64 @llvm.experimental.constrained.llround.i64.f32(float 42.0,
462                                                metadata !"fpexcept.strict") #0
463   ret i64 %result
466 ; Verify that sitofp(42) isn't simplified when the rounding mode is unknown.
467 ; CHECK-LABEL: @f30
468 ; CHECK: call double @llvm.experimental.constrained.sitofp
469 define double @f30() #0 {
470 entry:
471   %result = call double @llvm.experimental.constrained.sitofp.f64.i32(i32 42,
472                                                metadata !"round.dynamic",
473                                                metadata !"fpexcept.strict") #0
474   ret double %result
477 ; Verify that uitofp(42) isn't simplified when the rounding mode is unknown.
478 ; CHECK-LABEL: @f31
479 ; CHECK: call double @llvm.experimental.constrained.uitofp
480 define double @f31() #0 {
481 entry:
482   %result = call double @llvm.experimental.constrained.uitofp.f64.i32(i32 42,
483                                                metadata !"round.dynamic",
484                                                metadata !"fpexcept.strict") #0
485   ret double %result
488 attributes #0 = { strictfp }
490 @llvm.fp.env = thread_local global i8 zeroinitializer, section "llvm.metadata"
491 declare double @llvm.experimental.constrained.fdiv.f64(double, double, metadata, metadata)
492 declare double @llvm.experimental.constrained.fmul.f64(double, double, metadata, metadata)
493 declare double @llvm.experimental.constrained.fadd.f64(double, double, metadata, metadata)
494 declare double @llvm.experimental.constrained.fsub.f64(double, double, metadata, metadata)
495 declare double @llvm.experimental.constrained.sqrt.f64(double, metadata, metadata)
496 declare double @llvm.experimental.constrained.pow.f64(double, double, metadata, metadata)
497 declare double @llvm.experimental.constrained.powi.f64(double, i32, metadata, metadata)
498 declare double @llvm.experimental.constrained.sin.f64(double, metadata, metadata)
499 declare double @llvm.experimental.constrained.cos.f64(double, metadata, metadata)
500 declare double @llvm.experimental.constrained.tan.f64(double, metadata, metadata)
501 declare double @llvm.experimental.constrained.exp.f64(double, metadata, metadata)
502 declare double @llvm.experimental.constrained.exp2.f64(double, metadata, metadata)
503 declare double @llvm.experimental.constrained.log.f64(double, metadata, metadata)
504 declare double @llvm.experimental.constrained.log10.f64(double, metadata, metadata)
505 declare double @llvm.experimental.constrained.log2.f64(double, metadata, metadata)
506 declare double @llvm.experimental.constrained.rint.f64(double, metadata, metadata)
507 declare double @llvm.experimental.constrained.nearbyint.f64(double, metadata, metadata)
508 declare double @llvm.experimental.constrained.fma.f64(double, double, double, metadata, metadata)
509 declare i32 @llvm.experimental.constrained.fptosi.i32.f64(double, metadata)
510 declare i32 @llvm.experimental.constrained.fptoui.i32.f64(double, metadata)
511 declare float @llvm.experimental.constrained.fptrunc.f32.f64(double, metadata, metadata)
512 declare double @llvm.experimental.constrained.fpext.f64.f32(float, metadata)
513 declare i32 @llvm.experimental.constrained.lrint.i32.f64(double, metadata, metadata)
514 declare i32 @llvm.experimental.constrained.lrint.i32.f32(float, metadata, metadata)
515 declare i64 @llvm.experimental.constrained.llrint.i64.f64(double, metadata, metadata)
516 declare i64 @llvm.experimental.constrained.llrint.i64.f32(float, metadata, metadata)
517 declare i32 @llvm.experimental.constrained.lround.i32.f64(double, metadata)
518 declare i32 @llvm.experimental.constrained.lround.i32.f32(float, metadata)
519 declare i64 @llvm.experimental.constrained.llround.i64.f64(double, metadata)
520 declare i64 @llvm.experimental.constrained.llround.i64.f32(float, metadata)
521 declare double @llvm.experimental.constrained.sitofp.f64.i32(i32, metadata, metadata)
522 declare double @llvm.experimental.constrained.uitofp.f64.i32(i32, metadata, metadata)