Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / clang / test / CodeGen / fp-contract-pragma.cpp
blobc503bf69147c4a4197a0d5f3c4f7d87ab0f99e16
1 // RUN: %clang_cc1 -O3 -triple %itanium_abi_triple -emit-llvm -o - %s | FileCheck %s
3 // Is FP_CONTRACT honored in a simple case?
4 float fp_contract_1(float a, float b, float c) {
5 // CHECK: _Z13fp_contract_1fff
6 // CHECK: tail call float @llvm.fmuladd
7 #pragma STDC FP_CONTRACT ON
8 return a * b + c;
11 // Is FP_CONTRACT state cleared on exiting compound statements?
12 float fp_contract_2(float a, float b, float c) {
13 // CHECK: _Z13fp_contract_2fff
14 // CHECK: %[[M:.+]] = fmul float %a, %b
15 // CHECK-NEXT: fadd float %[[M]], %c
17 #pragma STDC FP_CONTRACT ON
19 return a * b + c;
22 // Does FP_CONTRACT survive template instantiation?
23 class Foo {};
24 Foo operator+(Foo, Foo);
26 template <typename T>
27 T template_muladd(T a, T b, T c) {
28 #pragma STDC FP_CONTRACT ON
29 return a * b + c;
32 float fp_contract_3(float a, float b, float c) {
33 // CHECK: _Z13fp_contract_3fff
34 // CHECK: tail call noundef float @llvm.fmuladd
35 return template_muladd<float>(a, b, c);
38 template<typename T> class fp_contract_4 {
39 float method(float a, float b, float c) {
40 #pragma STDC FP_CONTRACT ON
41 return a * b + c;
45 template class fp_contract_4<int>;
46 // CHECK: _ZN13fp_contract_4IiE6methodEfff
47 // CHECK: tail call float @llvm.fmuladd
49 // Check file-scoped FP_CONTRACT
50 #pragma STDC FP_CONTRACT ON
51 float fp_contract_5(float a, float b, float c) {
52 // CHECK: _Z13fp_contract_5fff
53 // CHECK: tail call float @llvm.fmuladd
54 return a * b + c;
57 #pragma STDC FP_CONTRACT OFF
58 float fp_contract_6(float a, float b, float c) {
59 // CHECK: _Z13fp_contract_6fff
60 // CHECK: %[[M:.+]] = fmul float %a, %b
61 // CHECK-NEXT: fadd float %[[M]], %c
62 return a * b + c;
65 // If the multiply has multiple uses, don't produce fmuladd.
66 // This used to assert (PR25719):
67 // https://llvm.org/bugs/show_bug.cgi?id=25719
69 float fp_contract_7(float a, float b, float c) {
70 // CHECK: _Z13fp_contract_7fff
71 // CHECK: %[[M:.+]] = fmul float %b, 2.000000e+00
72 // CHECK-NEXT: fsub float %[[M]], %c
73 #pragma STDC FP_CONTRACT ON
74 return (a = 2 * b) - c;
77 float fp_contract_8(float a, float b, float c) {
78 // CHECK: _Z13fp_contract_8fff
79 // CHECK: fneg float %c
80 // CHECK: tail call float @llvm.fmuladd
81 #pragma STDC FP_CONTRACT ON
82 return a * b - c;
85 float fp_contract_9(float a, float b, float c) {
86 // CHECK: _Z13fp_contract_9fff
87 // CHECK: fneg float %a
88 // CHECK: tail call float @llvm.fmuladd
89 #pragma STDC FP_CONTRACT ON
90 return c - a * b;
93 float fp_contract_10(float a, float b, float c) {
94 // CHECK: _Z14fp_contract_10fff
95 // CHECK: fneg float %a
96 // CHECK: tail call float @llvm.fmuladd
97 #pragma STDC FP_CONTRACT ON
98 return -(a * b) + c;
101 float fp_contract_11(float a, float b, float c) {
102 // CHECK: _Z14fp_contract_11fff
103 // CHECK: fneg float %a
104 // CHECK: fneg float %c
105 // CHECK: tail call float @llvm.fmuladd
106 #pragma STDC FP_CONTRACT ON
107 return -(a * b) - c;
110 float fp_contract_12(float a, float b, float c) {
111 // CHECK: _Z14fp_contract_12fff
112 // CHECK: fneg float %a
113 // CHECK: tail call float @llvm.fmuladd
114 #pragma STDC FP_CONTRACT ON
115 return c + -(a * b);
118 float fp_contract_13(float a, float b, float c) {
119 // CHECK: _Z14fp_contract_13fff
120 // CHECK-NOT: fneg float %a
121 // CHECK: tail call float @llvm.fmuladd
122 #pragma STDC FP_CONTRACT ON
123 return c - -(a * b);
126 float fp_contract_14(float a, float b, float c) {
127 // CHECK: _Z14fp_contract_14fff
128 // CHECK: %[[M:.+]] = fmul float %a, %b
129 // CHECK-NEXT: %add = fsub float %c, %[[M]]
130 #pragma STDC FP_CONTRACT ON
131 float d;
132 return (d = -(a * b)) + c;
135 float fp_contract_15(float a, float b, float c) {
136 // CHECK: _Z14fp_contract_15fff
137 // CHECK: %[[M:.+]] = fmul float %a, %b
138 // CHECK-NEXT: %add = fsub float %c, %[[M]]
139 #pragma STDC FP_CONTRACT ON
140 float d;
141 return -(d = (a * b)) + c;