aboutsummaryrefslogtreecommitdiff
path: root/test/CodeGen/fp-contract-pragma.cpp
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2012-10-02 04:45:10 +0000
committerLang Hames <lhames@gmail.com>2012-10-02 04:45:10 +0000
commitbe9af1288881110e406b87914162eaa59f1e5918 (patch)
treed5dad9578b613b3a7d8e5b6612e686b76bb22203 /test/CodeGen/fp-contract-pragma.cpp
parentd13eff6f77216a6fb25e18f600b492db4f0492e8 (diff)
Add FP_CONTRACT support for clang.
Clang will now honor the FP_CONTRACT pragma and emit LLVM fmuladd intrinsics for expressions of the form A * B + C (when they occur in a single statement). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164989 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGen/fp-contract-pragma.cpp')
-rw-r--r--test/CodeGen/fp-contract-pragma.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/CodeGen/fp-contract-pragma.cpp b/test/CodeGen/fp-contract-pragma.cpp
new file mode 100644
index 0000000000..8c51469c47
--- /dev/null
+++ b/test/CodeGen/fp-contract-pragma.cpp
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -O3 -emit-llvm -o - %s | FileCheck %s
+
+// Is FP_CONTRACT is honored in a simple case?
+float fp_contract_1(float a, float b, float c) {
+// CHECK: _Z13fp_contract_1fff
+// CHECK-NEXT: entry
+// CHECK-NEXT: %0 = tail call float @llvm.fmuladd
+ #pragma STDC FP_CONTRACT ON
+ return a * b + c;
+}
+
+// Is FP_CONTRACT state cleared on exiting compound statements?
+float fp_contract_2(float a, float b, float c) {
+// CHECK: _Z13fp_contract_2fff
+// CHECK-NEXT: entry
+// CHECK-NEXT: %mul = fmul float %a, %b
+// CHECK-NEXT: %add = fadd float %mul, %c
+ {
+ #pragma STDC FP_CONTRACT ON
+ }
+ return a * b + c;
+}
+
+// Does FP_CONTRACT survive template instatiation?
+class Foo {};
+Foo operator+(Foo, Foo);
+
+template <typename T>
+T template_muladd(T a, T b, T c) {
+ #pragma STDC FP_CONTRACT ON
+ return a * b + c;
+}
+
+float fp_contract_3(float a, float b, float c) {
+// CHECK: _Z13fp_contract_3fff
+// CHECK-NEXT: entry
+// CHECK-NEXT: %0 = tail call float @llvm.fmuladd
+ return template_muladd<float>(a, b, c);
+}