[pkg-d-commits] [ldc] 88/95: Implement @ldc.attributes.llvmFastMathFlag("contract") magic UDA.
Matthias Klumpp
mak at moszumanska.debian.org
Thu Jul 13 20:54:04 UTC 2017
This is an automated email from the git hooks/post-receive script.
mak pushed a commit to annotated tag v1.3.0-beta1
in repository ldc.
commit 9e9ff54ad67814f6dc1e52589d7a4b08b8affac9
Author: Johan Engelen <jbc.engelen at gmail.com>
Date: Mon Apr 3 22:55:43 2017 +0200
Implement @ldc.attributes.llvmFastMathFlag("contract") magic UDA.
Resolves issue #2059
---
gen/uda.cpp | 4 ++++
tests/codegen/attr_llvmFMF_contract.d | 20 ++++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/gen/uda.cpp b/gen/uda.cpp
index 69e7595..b6fee39 100644
--- a/gen/uda.cpp
+++ b/gen/uda.cpp
@@ -215,6 +215,10 @@ void applyAttrLLVMFastMathFlag(StructLiteralExp *sle, IrFunction *irFunc) {
irFunc->FMF.clear();
} else if (value == "fast") {
irFunc->FMF.setUnsafeAlgebra();
+#if LDC_LLVM_VER >= 500
+ } else if (value == "contract") {
+ irFunc->FMF.setAllowContract(true);
+#endif
} else if (value == "nnan") {
irFunc->FMF.setNoNaNs();
} else if (value == "ninf") {
diff --git a/tests/codegen/attr_llvmFMF_contract.d b/tests/codegen/attr_llvmFMF_contract.d
new file mode 100644
index 0000000..43dd6f7
--- /dev/null
+++ b/tests/codegen/attr_llvmFMF_contract.d
@@ -0,0 +1,20 @@
+// Tests the @ldc.attributes.llvmFastMathFlag("contract") UDA
+// Also tests that adding this attribute indeed leads to LLVM optimizing it to a fused multiply-add for a simple case.
+
+// REQUIRES: atleast_llvm500, target_X86
+
+// RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s --check-prefix LLVM < %t.ll
+// RUN: %ldc -betterC -mtriple=x86_64-linux-gnu -mattr=+fma -O3 -release -c -output-s -of=%t.s %s && FileCheck %s --check-prefix ASM < %t.s
+
+import ldc.attributes;
+
+// LLVM-LABEL: define{{.*}} @{{.*}}contract
+// ASM-LABEL: contract:
+ at llvmFastMathFlag("contract")
+extern(C) double contract(double a, double b, double c)
+{
+// LLVM: fmul contract double
+// LLVM: fadd contract double
+// ASM: vfmadd
+ return a * b + c;
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git
More information about the pkg-d-commits
mailing list