[clang] d261660 - Fix the use of -fno-approx-func along with -Ofast or -ffast-math
Masoud Ataei via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 19 08:06:43 PST 2022
Author: Masoud Ataei
Date: 2022-01-19T08:05:08-08:00
New Revision: d261660af96d402689d025b4584e925869a9b413
URL: https://github.com/llvm/llvm-project/commit/d261660af96d402689d025b4584e925869a9b413
DIFF: https://github.com/llvm/llvm-project/commit/d261660af96d402689d025b4584e925869a9b413.diff
LOG: Fix the use of -fno-approx-func along with -Ofast or -ffast-math
Fix how -fapprox-func interact correctly with the other floating point options.
Reported bug Number 52565: https://bugs.llvm.org/show_bug.cgi?id=52565
Differential: https://reviews.llvm.org/D114564
Reviewer: @andrew.w.kaylor
Added:
Modified:
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/fast-math.c
clang/test/Preprocessor/aarch64-target-features.c
clang/test/Preprocessor/arm-target-features.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index fd300fbe40145..253c52cf0ba85 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2902,6 +2902,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
AssociativeMath = true;
ReciprocalMath = true;
SignedZeros = false;
+ ApproxFunc = true;
TrappingMath = false;
FPExceptionBehavior = "";
break;
@@ -2909,6 +2910,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
AssociativeMath = false;
ReciprocalMath = false;
SignedZeros = true;
+ ApproxFunc = false;
TrappingMath = true;
FPExceptionBehavior = "strict";
@@ -2928,6 +2930,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
MathErrno = false;
AssociativeMath = true;
ReciprocalMath = true;
+ ApproxFunc = true;
SignedZeros = false;
TrappingMath = false;
RoundingFPMath = false;
@@ -2943,6 +2946,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
MathErrno = TC.IsMathErrnoDefault();
AssociativeMath = false;
ReciprocalMath = false;
+ ApproxFunc = false;
SignedZeros = true;
// -fno_fast_math restores default denormal and fpcontract handling
DenormalFPMath = DefaultDenormalFPMath;
@@ -2961,7 +2965,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
// If -ffp-model=strict has been specified on command line but
// subsequent options conflict then emit warning diagnostic.
if (HonorINFs && HonorNaNs && !AssociativeMath && !ReciprocalMath &&
- SignedZeros && TrappingMath && RoundingFPMath &&
+ SignedZeros && TrappingMath && RoundingFPMath && !ApproxFunc &&
DenormalFPMath == llvm::DenormalMode::getIEEE() &&
DenormalFP32Math == llvm::DenormalMode::getIEEE() &&
FPContract.equals("off"))
@@ -2994,7 +2998,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
CmdArgs.push_back("-fmath-errno");
if (!MathErrno && AssociativeMath && ReciprocalMath && !SignedZeros &&
- !TrappingMath)
+ ApproxFunc && !TrappingMath)
CmdArgs.push_back("-menable-unsafe-fp-math");
if (!SignedZeros)
@@ -3045,7 +3049,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
// -ffast-math enables the __FAST_MATH__ preprocessor macro, but check for the
// individual features enabled by -ffast-math instead of the option itself as
// that's consistent with gcc's behaviour.
- if (!HonorINFs && !HonorNaNs && !MathErrno && AssociativeMath &&
+ if (!HonorINFs && !HonorNaNs && !MathErrno && AssociativeMath && ApproxFunc &&
ReciprocalMath && !SignedZeros && !TrappingMath && !RoundingFPMath) {
CmdArgs.push_back("-ffast-math");
if (FPModel.equals("fast")) {
diff --git a/clang/test/Driver/fast-math.c b/clang/test/Driver/fast-math.c
index 8d293c2ea01ff..a66e9d0eca177 100644
--- a/clang/test/Driver/fast-math.c
+++ b/clang/test/Driver/fast-math.c
@@ -70,6 +70,23 @@
// CHECK-NO-NANS-NO-FAST-MATH: "-cc1"
// CHECK-NO-NANS-NO-FAST-MATH-NOT: "-menable-no-nans"
//
+// RUN: %clang -### -ffast-math -fno-approx-func -c %s 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-FAST-MATH-NO-APPROX-FUNC %s
+// CHECK-FAST-MATH-NO-APPROX-FUNC: "-cc1"
+// CHECK-FAST-MATH-NO-APPROX-FUNC: "-menable-no-infs"
+// CHECK-FAST-MATH-NO-APPROX-FUNC: "-menable-no-nans"
+// CHECK-FAST-MATH-NO-APPROX-FUNC: "-fno-signed-zeros"
+// CHECK-FAST-MATH-NO-APPROX-FUNC: "-mreassociate"
+// CHECK-FAST-MATH-NO-APPROX-FUNC: "-freciprocal-math"
+// CHECK-FAST-MATH-NO-APPROX-FUNC: "-ffp-contract=fast"
+// CHECK-FAST-MATH-NO-APPROX-FUNC-NOT: "-ffast-math"
+// CHECK-FAST-MATH-NO-APPROX-FUNC-NOT: "-fapprox-func"
+//
+// RUN: %clang -### -fno-approx-func -ffast-math -c %s 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-NO-APPROX-FUNC-FAST-MATH %s
+// CHECK-NO-APPROX-FUNC-FAST-MATH: "-cc1"
+// CHECK-NO-APPROX-FUNC-FAST-MATH: "-ffast-math"
+//
// RUN: %clang -### -fapprox-func -c %s 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-APPROX-FUNC %s
// CHECK-APPROX-FUNC: "-cc1"
@@ -130,14 +147,14 @@
// RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
//
// RUN: %clang -### -fno-math-errno -fassociative-math -freciprocal-math \
-// RUN: -fno-signed-zeros -fno-trapping-math -c %s 2>&1 \
+// RUN: -fno-signed-zeros -fno-trapping-math -fapprox-func -c %s 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s
// CHECK-UNSAFE-MATH: "-cc1"
// CHECK-UNSAFE-MATH: "-menable-unsafe-fp-math"
// CHECK-UNSAFE-MATH: "-mreassociate"
//
// RUN: %clang -### -fno-fast-math -fno-math-errno -fassociative-math -freciprocal-math \
-// RUN: -fno-signed-zeros -fno-trapping-math -c %s 2>&1 \
+// RUN: -fno-signed-zeros -fno-trapping-math -fapprox-func -c %s 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-NO-FAST-MATH-UNSAFE-MATH %s
// CHECK-NO-FAST-MATH-UNSAFE-MATH: "-cc1"
// CHECK-NO-FAST-MATH-UNSAFE-MATH: "-menable-unsafe-fp-math"
@@ -178,7 +195,7 @@
// RUN: -fno-math-errno -ffp-contract=fast -fno-rounding-math -c %s 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-FAST-MATH %s
// RUN: %clang -### -fno-honor-infinities -fno-honor-nans -fno-math-errno \
-// RUN: -fassociative-math -freciprocal-math -fno-signed-zeros \
+// RUN: -fassociative-math -freciprocal-math -fno-signed-zeros -fapprox-func \
// RUN: -fno-trapping-math -ffp-contract=fast -fno-rounding-math -c %s 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-FAST-MATH %s
// CHECK-FAST-MATH: "-cc1"
diff --git a/clang/test/Preprocessor/aarch64-target-features.c b/clang/test/Preprocessor/aarch64-target-features.c
index d063f188b68ab..3461af3ecbd20 100644
--- a/clang/test/Preprocessor/aarch64-target-features.c
+++ b/clang/test/Preprocessor/aarch64-target-features.c
@@ -115,7 +115,7 @@
// CHECK-CRC32: __ARM_FEATURE_CRC32 1
// RUN: %clang -target aarch64-none-linux-gnu -fno-math-errno -fno-signed-zeros\
-// RUN: -fno-trapping-math -fassociative-math -freciprocal-math\
+// RUN: -fno-trapping-math -fassociative-math -freciprocal-math -fapprox-func\
// RUN: -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FASTMATH %s
// RUN: %clang -target aarch64-none-linux-gnu -ffast-math -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FASTMATH %s
// RUN: %clang -target arm64-none-linux-gnu -ffast-math -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FASTMATH %s
diff --git a/clang/test/Preprocessor/arm-target-features.c b/clang/test/Preprocessor/arm-target-features.c
index 81531a39f29f5..d1a313b675cdf 100644
--- a/clang/test/Preprocessor/arm-target-features.c
+++ b/clang/test/Preprocessor/arm-target-features.c
@@ -267,7 +267,7 @@
// CHECK-DEFS:#define __ARM_SIZEOF_WCHAR_T 4
// RUN: %clang -target arm-none-linux-gnu -fno-math-errno -fno-signed-zeros\
-// RUN: -fno-trapping-math -fassociative-math -freciprocal-math\
+// RUN: -fno-trapping-math -fassociative-math -freciprocal-math -fapprox-func\
// RUN: -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FASTMATH %s
// RUN: %clang -target arm-none-linux-gnu -ffast-math -x c -E -dM %s -o -\
// RUN: | FileCheck -match-full-lines --check-prefix=CHECK-FASTMATH %s
More information about the cfe-commits
mailing list