1 // RUN: %clang_cc1 -O3 -triple %itanium_abi_triple \
2 // RUN: -emit-llvm -o - %s \
3 // RUN: | FileCheck -check-prefixes=COMMON,CHECK %s
4 // RUN: %clang_cc1 -fexperimental-strict-floating-point \
5 // RUN: -ffp-exception-behavior=strict -O3 \
6 // RUN: -triple %itanium_abi_triple -emit-llvm -o - %s \
7 // RUN: | FileCheck -check-prefixes=COMMON,STRICT %s
9 // Is FP_CONTRACT honored in a simple case?
10 float fp_contract_1(float a
, float b
, float c
) {
11 // COMMON: _Z13fp_contract_1fff
12 // CHECK: %[[M:.+]] = fmul contract float %a, %b
13 // CHECK-NEXT: fadd contract float %[[M]], %c
14 // STRICT: %[[M:.+]] = tail call contract float @llvm.experimental.constrained.fmul.f32(float %a, float %b, metadata !"round.tonearest", metadata !"fpexcept.strict")
15 // STRICT-NEXT: tail call contract float @llvm.experimental.constrained.fadd.f32(float %[[M]], float %c, metadata !"round.tonearest", metadata !"fpexcept.strict")
17 #pragma clang fp contract(fast)
21 // Is FP_CONTRACT state cleared on exiting compound statements?
22 float fp_contract_2(float a
, float b
, float c
) {
23 // COMMON: _Z13fp_contract_2fff
24 // CHECK: %[[M:.+]] = fmul float %a, %b
25 // CHECK-NEXT: fadd float %[[M]], %c
26 // STRICT: %[[M:.+]] = tail call float @llvm.experimental.constrained.fmul.f32(float %a, float %b, metadata !"round.tonearest", metadata !"fpexcept.strict")
27 // STRICT-NEXT: tail call float @llvm.experimental.constrained.fadd.f32(float %[[M]], float %c, metadata !"round.tonearest", metadata !"fpexcept.strict")
29 #pragma clang fp contract(fast)
34 // Does FP_CONTRACT survive template instantiation?
36 Foo
operator+(Foo
, Foo
);
39 T
template_muladd(T a
, T b
, T c
) {
40 #pragma clang fp contract(fast)
44 float fp_contract_3(float a
, float b
, float c
) {
45 // COMMON: _Z13fp_contract_3fff
46 // CHECK: %[[M:.+]] = fmul contract float %a, %b
47 // CHECK-NEXT: fadd contract float %[[M]], %c
48 // STRICT: %[[M:.+]] = tail call contract float @llvm.experimental.constrained.fmul.f32(float %a, float %b, metadata !"round.tonearest", metadata !"fpexcept.strict")
49 // STRICT-NEXT: tail call contract noundef float @llvm.experimental.constrained.fadd.f32(float %[[M]], float %c, metadata !"round.tonearest", metadata !"fpexcept.strict")
50 return template_muladd
<float>(a
, b
, c
);
55 float method(float a
, float b
, float c
) {
56 #pragma clang fp contract(fast)
61 template class fp_contract_4
<int>;
62 // COMMON: _ZN13fp_contract_4IiE6methodEfff
63 // CHECK: %[[M:.+]] = fmul contract float %a, %b
64 // CHECK-NEXT: fadd contract float %[[M]], %c
65 // STRICT: %[[M:.+]] = tail call contract float @llvm.experimental.constrained.fmul.f32(float %a, float %b, metadata !"round.tonearest", metadata !"fpexcept.strict")
66 // STRICT-NEXT: tail call contract float @llvm.experimental.constrained.fadd.f32(float %[[M]], float %c, metadata !"round.tonearest", metadata !"fpexcept.strict")
68 // Check file-scoped FP_CONTRACT
69 #pragma clang fp contract(fast)
70 float fp_contract_5(float a
, float b
, float c
) {
71 // COMMON: _Z13fp_contract_5fff
72 // CHECK: %[[M:.+]] = fmul contract float %a, %b
73 // CHECK-NEXT: fadd contract float %[[M]], %c
74 // STRICT: %[[M:.+]] = tail call contract float @llvm.experimental.constrained.fmul.f32(float %a, float %b, metadata !"round.tonearest", metadata !"fpexcept.strict")
75 // STRICT-NEXT: tail call contract float @llvm.experimental.constrained.fadd.f32(float %[[M]], float %c, metadata !"round.tonearest", metadata !"fpexcept.strict")
79 // Verify that we can handle multiple flags on the same pragma
80 #pragma clang fp contract(fast) contract(off)
81 float fp_contract_6(float a
, float b
, float c
) {
82 // COMMON: _Z13fp_contract_6fff
83 // CHECK: %[[M:.+]] = fmul float %a, %b
84 // CHECK-NEXT: fadd float %[[M]], %c
85 // STRICT: %[[M:.+]] = tail call float @llvm.experimental.constrained.fmul.f32(float %a, float %b, metadata !"round.tonearest", metadata !"fpexcept.strict")
86 // STRICT-NEXT: tail call float @llvm.experimental.constrained.fadd.f32(float %[[M]], float %c, metadata !"round.tonearest", metadata !"fpexcept.strict")
91 #pragma clang fp contract(fast)
92 float fp_contract_7(float a
) {
93 // COMMON: _Z13fp_contract_7f
94 // CHECK: tail call contract float @llvm.sqrt.f32(float %a)
95 // STRICT: tail call contract float @llvm.experimental.constrained.sqrt.f32(float %a, metadata !"round.tonearest", metadata !"fpexcept.strict")
96 return __builtin_sqrtf(a
);
99 float fp_contract_8(float a
) {
100 // COMMON: _Z13fp_contract_8f
101 // CHECK: tail call float @llvm.sqrt.f32(float %a)
102 // STRICT: tail call float @llvm.experimental.constrained.sqrt.f32(float %a, metadata !"round.tonearest", metadata !"fpexcept.strict")
103 #pragma clang fp contract(off)
104 return __builtin_sqrtf(a
);