Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGen / fp-contract-fast-pragma.cpp
blob0bb01d6e17a1d6d3631b08a4024e4c1401407b0e
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)
18 return a * b + c;
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)
31 return a * b + c;
34 // Does FP_CONTRACT survive template instantiation?
35 class Foo {};
36 Foo operator+(Foo, Foo);
38 template <typename T>
39 T template_muladd(T a, T b, T c) {
40 #pragma clang fp contract(fast)
41 return a * b + c;
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);
53 template <typename T>
54 class fp_contract_4 {
55 float method(float a, float b, float c) {
56 #pragma clang fp contract(fast)
57 return a * b + c;
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")
76 return a * b + c;
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")
87 return a * b + c;
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);