1 ; RUN: llc -O3 -mtriple=x86_64-pc-linux < %s | FileCheck --check-prefix=COMMON --check-prefix=NO-FMA --check-prefix=FMACALL64 --check-prefix=FMACALL32 %s
2 ; RUN: llc -O3 -mtriple=x86_64-pc-linux -mattr=+fma < %s | FileCheck -check-prefix=COMMON --check-prefix=HAS-FMA --check-prefix=FMA64 --check-prefix=FMA32 %s
4 ; Verify that constants aren't folded to inexact results when the rounding mode
8 ; // Because 0.1 cannot be represented exactly, this shouldn't be folded.
16 %div = call double @llvm.experimental.constrained.fdiv.f64(
19 metadata !"round.dynamic",
20 metadata !"fpexcept.strict")
24 ; Verify that 'a - 0' isn't simplified to 'a' when the rounding mode is unknown.
26 ; double f2(double a) {
27 ; // Because the result of '0 - 0' is negative zero if rounding mode is
28 ; // downward, this shouldn't be simplified.
34 define double @f2(double %a) {
36 %sub = call double @llvm.experimental.constrained.fsub.f64(
39 metadata !"round.dynamic",
40 metadata !"fpexcept.strict")
44 ; Verify that '-((-a)*b)' isn't simplified to 'a*b' when the rounding mode is
47 ; double f3(double a, double b) {
48 ; // Because the intermediate value involved in this calculation may require
49 ; // rounding, this shouldn't be simplified.
57 define double @f3(double %a, double %b) {
59 %sub = call double @llvm.experimental.constrained.fsub.f64(
60 double -0.000000e+00, double %a,
61 metadata !"round.dynamic",
62 metadata !"fpexcept.strict")
63 %mul = call double @llvm.experimental.constrained.fmul.f64(
64 double %sub, double %b,
65 metadata !"round.dynamic",
66 metadata !"fpexcept.strict")
67 %ret = call double @llvm.experimental.constrained.fsub.f64(
70 metadata !"round.dynamic",
71 metadata !"fpexcept.strict")
75 ; Verify that FP operations are not performed speculatively when FP exceptions
76 ; are not being ignored.
78 ; double f4(int n, double a) {
79 ; // Because a + 1 may overflow, this should not be simplified.
90 define double @f4(i32 %n, double %a) {
92 %cmp = icmp sgt i32 %n, 0
93 br i1 %cmp, label %if.then, label %if.end
96 %add = call double @llvm.experimental.constrained.fadd.f64(
97 double 1.000000e+00, double %a,
98 metadata !"round.dynamic",
99 metadata !"fpexcept.strict")
103 %a.0 = phi double [%add, %if.then], [ %a, %entry ]
107 ; Verify that sqrt(42.0) isn't simplified when the rounding mode is unknown.
110 define double @f5() {
112 %result = call double @llvm.experimental.constrained.sqrt.f64(double 42.0,
113 metadata !"round.dynamic",
114 metadata !"fpexcept.strict")
118 ; Verify that pow(42.1, 3.0) isn't simplified when the rounding mode is unknown.
121 define double @f6() {
123 %result = call double @llvm.experimental.constrained.pow.f64(double 42.1,
125 metadata !"round.dynamic",
126 metadata !"fpexcept.strict")
130 ; Verify that powi(42.1, 3) isn't simplified when the rounding mode is unknown.
133 define double @f7() {
135 %result = call double @llvm.experimental.constrained.powi.f64(double 42.1,
137 metadata !"round.dynamic",
138 metadata !"fpexcept.strict")
142 ; Verify that sin(42.0) isn't simplified when the rounding mode is unknown.
145 define double @f8() {
147 %result = call double @llvm.experimental.constrained.sin.f64(double 42.0,
148 metadata !"round.dynamic",
149 metadata !"fpexcept.strict")
153 ; Verify that cos(42.0) isn't simplified when the rounding mode is unknown.
156 define double @f9() {
158 %result = call double @llvm.experimental.constrained.cos.f64(double 42.0,
159 metadata !"round.dynamic",
160 metadata !"fpexcept.strict")
164 ; Verify that exp(42.0) isn't simplified when the rounding mode is unknown.
167 define double @f10() {
169 %result = call double @llvm.experimental.constrained.exp.f64(double 42.0,
170 metadata !"round.dynamic",
171 metadata !"fpexcept.strict")
175 ; Verify that exp2(42.1) isn't simplified when the rounding mode is unknown.
178 define double @f11() {
180 %result = call double @llvm.experimental.constrained.exp2.f64(double 42.1,
181 metadata !"round.dynamic",
182 metadata !"fpexcept.strict")
186 ; Verify that log(42.0) isn't simplified when the rounding mode is unknown.
189 define double @f12() {
191 %result = call double @llvm.experimental.constrained.log.f64(double 42.0,
192 metadata !"round.dynamic",
193 metadata !"fpexcept.strict")
197 ; Verify that log10(42.0) isn't simplified when the rounding mode is unknown.
200 define double @f13() {
202 %result = call double @llvm.experimental.constrained.log10.f64(double 42.0,
203 metadata !"round.dynamic",
204 metadata !"fpexcept.strict")
208 ; Verify that log2(42.0) isn't simplified when the rounding mode is unknown.
211 define double @f14() {
213 %result = call double @llvm.experimental.constrained.log2.f64(double 42.0,
214 metadata !"round.dynamic",
215 metadata !"fpexcept.strict")
219 ; Verify that rint(42.1) isn't simplified when the rounding mode is unknown.
223 define double @f15() {
225 %result = call double @llvm.experimental.constrained.rint.f64(double 42.1,
226 metadata !"round.dynamic",
227 metadata !"fpexcept.strict")
231 ; Verify that nearbyint(42.1) isn't simplified when the rounding mode is
236 define double @f16() {
238 %result = call double @llvm.experimental.constrained.nearbyint.f64(
240 metadata !"round.dynamic",
241 metadata !"fpexcept.strict")
245 ; Verify that fma(3.5) isn't simplified when the rounding mode is
248 ; FMACALL32: jmp fmaf # TAILCALL
250 define float @f17() {
252 %result = call float @llvm.experimental.constrained.fma.f32(
256 metadata !"round.dynamic",
257 metadata !"fpexcept.strict")
261 ; Verify that fma(42.1) isn't simplified when the rounding mode is
264 ; FMACALL64: jmp fma # TAILCALL
266 define double @f18() {
268 %result = call double @llvm.experimental.constrained.fma.f64(
272 metadata !"round.dynamic",
273 metadata !"fpexcept.strict")
279 define double @f19() {
281 %rem = call double @llvm.experimental.constrained.frem.f64(
284 metadata !"round.dynamic",
285 metadata !"fpexcept.strict")
289 ; Verify that round(42.1) isn't simplified when the rounding mode is
291 ; Verify that no gross errors happen.
294 define float @f21() {
296 %result = call float @llvm.experimental.constrained.fptrunc.f32.f64(
298 metadata !"round.dynamic",
299 metadata !"fpexcept.strict")
305 define double @f22(float %x) {
307 %result = call double @llvm.experimental.constrained.fpext.f64.f32(float %x,
308 metadata !"fpexcept.strict")
312 @llvm.fp.env = thread_local global i8 zeroinitializer, section "llvm.metadata"
313 declare double @llvm.experimental.constrained.fadd.f64(double, double, metadata, metadata)
314 declare double @llvm.experimental.constrained.fsub.f64(double, double, metadata, metadata)
315 declare double @llvm.experimental.constrained.fmul.f64(double, double, metadata, metadata)
316 declare double @llvm.experimental.constrained.fdiv.f64(double, double, metadata, metadata)
317 declare double @llvm.experimental.constrained.frem.f64(double, double, metadata, metadata)
318 declare double @llvm.experimental.constrained.sqrt.f64(double, metadata, metadata)
319 declare double @llvm.experimental.constrained.pow.f64(double, double, metadata, metadata)
320 declare double @llvm.experimental.constrained.powi.f64(double, i32, metadata, metadata)
321 declare double @llvm.experimental.constrained.sin.f64(double, metadata, metadata)
322 declare double @llvm.experimental.constrained.cos.f64(double, metadata, metadata)
323 declare double @llvm.experimental.constrained.exp.f64(double, metadata, metadata)
324 declare double @llvm.experimental.constrained.exp2.f64(double, metadata, metadata)
325 declare double @llvm.experimental.constrained.log.f64(double, metadata, metadata)
326 declare double @llvm.experimental.constrained.log10.f64(double, metadata, metadata)
327 declare double @llvm.experimental.constrained.log2.f64(double, metadata, metadata)
328 declare double @llvm.experimental.constrained.rint.f64(double, metadata, metadata)
329 declare double @llvm.experimental.constrained.nearbyint.f64(double, metadata, metadata)
330 declare float @llvm.experimental.constrained.fma.f32(float, float, float, metadata, metadata)
331 declare double @llvm.experimental.constrained.fma.f64(double, double, double, metadata, metadata)
332 declare float @llvm.experimental.constrained.fptrunc.f32.f64(double, metadata, metadata)
333 declare double @llvm.experimental.constrained.fpext.f64.f32(float, metadata)