Hi,
I would like to submit the following patch for review:
[PATCH] Use CodeGenOptions to derive LLVM-IR fast math flags
The clang driver goes a long way to properly detangle the interactions
of the different fast math driver flags (test/Driver/fast-math.c). The
subsequent call to clang -cc1 then uses the CodeGenOption flags to set
the valid optimizations and it uses the LangOptions to enable the
relevant fast math macros.
When deriving the LLVM-IR fast math flags we use the CodeGenOptions,
instead of the previously used LangOptions. This ensures that
optimizations for the following command line are disabled, while the
fast math macro is still set:
clang -ffast-math -fno-finite-math-only -fno-unsafe-math-optimizations
file.c
Cheers,
Tobias
>From 0277c074163bc28ad8163d092274e66d41108371 Mon Sep 17 00:00:00 2001
From: Tobias Grosser <[email protected]>
Date: Fri, 9 Aug 2013 16:01:39 -0700
Subject: [PATCH] Use CodeGenOptions to derive LLVM-IR fast math flags
The clang driver goes a long way to properly detangle the interactions of the
different fast math driver flags (test/Driver/fast-math.c). The subsequent call
to clang -cc1 then uses the CodeGenOption flags to set the valid optimizations
and it uses the LangOptions to enable the relevant fast math macros.
When deriving the LLVM-IR fast math flags we use the CodeGenOptions, instead
of the previously used LangOptions. This ensures that optimizations for the
following command line are disabled, while the fast math macro is still set:
clang -ffast-math -fno-finite-math-only -fno-unsafe-math-optimizations file.c
---
lib/CodeGen/CodeGenFunction.cpp | 12 ++++++++----
test/CodeGen/fast-math.c | 11 -----------
test/CodeGen/finite-math.c | 11 -----------
test/CodeGen/no-infinites.c | 11 +++++++++++
test/CodeGen/no-nans.c | 11 +++++++++++
test/CodeGen/unsafe-fp-math.c | 11 +++++++++++
6 files changed, 41 insertions(+), 26 deletions(-)
delete mode 100644 test/CodeGen/fast-math.c
delete mode 100644 test/CodeGen/finite-math.c
create mode 100644 test/CodeGen/no-infinites.c
create mode 100644 test/CodeGen/no-nans.c
create mode 100644 test/CodeGen/unsafe-fp-math.c
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index 20352f9..91ee8f3 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/lib/CodeGen/CodeGenFunction.cpp
@@ -52,12 +52,16 @@ CodeGenFunction::CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext)
CGM.getCXXABI().getMangleContext().startNewFunction();
llvm::FastMathFlags FMF;
- if (CGM.getLangOpts().FastMath)
- FMF.setUnsafeAlgebra();
- if (CGM.getLangOpts().FiniteMathOnly) {
+
+ if (CGM.getCodeGenOpts().NoNaNsFPMath)
FMF.setNoNaNs();
+
+ if (CGM.getCodeGenOpts().NoInfsFPMath)
FMF.setNoInfs();
- }
+
+ if (CGM.getCodeGenOpts().UnsafeFPMath)
+ FMF.setUnsafeAlgebra();
+
Builder.SetFastMathFlags(FMF);
}
diff --git a/test/CodeGen/fast-math.c b/test/CodeGen/fast-math.c
deleted file mode 100644
index 4a51358..0000000
--- a/test/CodeGen/fast-math.c
+++ /dev/null
@@ -1,11 +0,0 @@
-// RUN: %clang_cc1 -ffast-math -emit-llvm -o - %s | FileCheck %s
-float f0, f1, f2;
-
-void foo(void) {
- // CHECK-LABEL: define void @foo()
-
- // CHECK: fadd fast
- f0 = f1 + f2;
-
- // CHECK: ret
-}
diff --git a/test/CodeGen/finite-math.c b/test/CodeGen/finite-math.c
deleted file mode 100644
index b0ee157..0000000
--- a/test/CodeGen/finite-math.c
+++ /dev/null
@@ -1,11 +0,0 @@
-// RUN: %clang_cc1 -ffinite-math-only -emit-llvm -o - %s | FileCheck %s
-float f0, f1, f2;
-
-void foo(void) {
- // CHECK-LABEL: define void @foo()
-
- // CHECK: fadd nnan ninf
- f0 = f1 + f2;
-
- // CHECK: ret
-}
diff --git a/test/CodeGen/no-infinites.c b/test/CodeGen/no-infinites.c
new file mode 100644
index 0000000..3aee5a8
--- /dev/null
+++ b/test/CodeGen/no-infinites.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -menable-no-infs -emit-llvm -o - %s | FileCheck %s
+float f0, f1, f2;
+
+void foo(void) {
+ // CHECK-LABEL: define void @foo()
+
+ // CHECK: fadd ninf float
+ f0 = f1 + f2;
+
+ // CHECK: ret
+}
diff --git a/test/CodeGen/no-nans.c b/test/CodeGen/no-nans.c
new file mode 100644
index 0000000..d59c5f3
--- /dev/null
+++ b/test/CodeGen/no-nans.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -menable-no-nans -emit-llvm -o - %s | FileCheck %s
+float f0, f1, f2;
+
+void foo(void) {
+ // CHECK: define void @foo()
+
+ // CHECK: fadd nnan float
+ f0 = f1 + f2;
+
+ // CHECK: ret
+}
diff --git a/test/CodeGen/unsafe-fp-math.c b/test/CodeGen/unsafe-fp-math.c
new file mode 100644
index 0000000..8603739
--- /dev/null
+++ b/test/CodeGen/unsafe-fp-math.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -menable-unsafe-fp-math -emit-llvm -o - %s | FileCheck %s
+float f0, f1, f2;
+
+void foo(void) {
+ // CHECK-LABEL: define void @foo()
+
+ // CHECK: fadd fast
+ f0 = f1 + f2;
+
+ // CHECK: ret
+}
--
1.8.1.2
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits