xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/fp-contract-pragma.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -O3 -triple %itanium_abi_triple -emit-llvm -o - %s | FileCheck %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc // Is FP_CONTRACT is honored in a simple case?
fp_contract_1(float a,float b,float c)4f4a2713aSLionel Sambuc float fp_contract_1(float a, float b, float c) {
5f4a2713aSLionel Sambuc // CHECK: _Z13fp_contract_1fff
6f4a2713aSLionel Sambuc // CHECK: tail call float @llvm.fmuladd
7f4a2713aSLionel Sambuc   #pragma STDC FP_CONTRACT ON
8f4a2713aSLionel Sambuc   return a * b + c;
9f4a2713aSLionel Sambuc }
10f4a2713aSLionel Sambuc 
11f4a2713aSLionel Sambuc // Is FP_CONTRACT state cleared on exiting compound statements?
fp_contract_2(float a,float b,float c)12f4a2713aSLionel Sambuc float fp_contract_2(float a, float b, float c) {
13f4a2713aSLionel Sambuc // CHECK: _Z13fp_contract_2fff
14f4a2713aSLionel Sambuc // CHECK: %[[M:.+]] = fmul float %a, %b
15f4a2713aSLionel Sambuc // CHECK-NEXT: fadd float %[[M]], %c
16f4a2713aSLionel Sambuc   {
17f4a2713aSLionel Sambuc     #pragma STDC FP_CONTRACT ON
18f4a2713aSLionel Sambuc   }
19f4a2713aSLionel Sambuc   return a * b + c;
20f4a2713aSLionel Sambuc }
21f4a2713aSLionel Sambuc 
22f4a2713aSLionel Sambuc // Does FP_CONTRACT survive template instatiation?
23f4a2713aSLionel Sambuc class Foo {};
24f4a2713aSLionel Sambuc Foo operator+(Foo, Foo);
25f4a2713aSLionel Sambuc 
26f4a2713aSLionel Sambuc template <typename T>
template_muladd(T a,T b,T c)27f4a2713aSLionel Sambuc T template_muladd(T a, T b, T c) {
28f4a2713aSLionel Sambuc   #pragma STDC FP_CONTRACT ON
29f4a2713aSLionel Sambuc   return a * b + c;
30f4a2713aSLionel Sambuc }
31f4a2713aSLionel Sambuc 
fp_contract_3(float a,float b,float c)32f4a2713aSLionel Sambuc float fp_contract_3(float a, float b, float c) {
33f4a2713aSLionel Sambuc // CHECK: _Z13fp_contract_3fff
34f4a2713aSLionel Sambuc // CHECK: tail call float @llvm.fmuladd
35f4a2713aSLionel Sambuc   return template_muladd<float>(a, b, c);
36f4a2713aSLionel Sambuc }
37f4a2713aSLionel Sambuc 
38f4a2713aSLionel Sambuc template<typename T> class fp_contract_4 {
method(float a,float b,float c)39f4a2713aSLionel Sambuc   float method(float a, float b, float c) {
40f4a2713aSLionel Sambuc     #pragma STDC FP_CONTRACT ON
41f4a2713aSLionel Sambuc     return a * b + c;
42f4a2713aSLionel Sambuc   }
43f4a2713aSLionel Sambuc };
44f4a2713aSLionel Sambuc 
45f4a2713aSLionel Sambuc template class fp_contract_4<int>;
46f4a2713aSLionel Sambuc // CHECK: _ZN13fp_contract_4IiE6methodEfff
47f4a2713aSLionel Sambuc // CHECK: tail call float @llvm.fmuladd
48f4a2713aSLionel Sambuc 
49f4a2713aSLionel Sambuc // Check file-scoped FP_CONTRACT
50f4a2713aSLionel Sambuc #pragma STDC FP_CONTRACT ON
fp_contract_5(float a,float b,float c)51f4a2713aSLionel Sambuc float fp_contract_5(float a, float b, float c) {
52f4a2713aSLionel Sambuc // CHECK: _Z13fp_contract_5fff
53f4a2713aSLionel Sambuc // CHECK: tail call float @llvm.fmuladd
54f4a2713aSLionel Sambuc   return a * b + c;
55f4a2713aSLionel Sambuc }
56f4a2713aSLionel Sambuc 
57f4a2713aSLionel Sambuc #pragma STDC FP_CONTRACT OFF
fp_contract_6(float a,float b,float c)58f4a2713aSLionel Sambuc float fp_contract_6(float a, float b, float c) {
59f4a2713aSLionel Sambuc // CHECK: _Z13fp_contract_6fff
60f4a2713aSLionel Sambuc // CHECK: %[[M:.+]] = fmul float %a, %b
61f4a2713aSLionel Sambuc // CHECK-NEXT: fadd float %[[M]], %c
62f4a2713aSLionel Sambuc   return a * b + c;
63f4a2713aSLionel Sambuc }
64f4a2713aSLionel Sambuc 
65