[clang] 3a95d7d - [clang] Fix -fp-model={strict|precise} to disable -fapprox-func
KAWASHIMA Takahiro via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 21 20:05:29 PST 2022
Author: KAWASHIMA Takahiro
Date: 2022-11-22T13:04:26+09:00
New Revision: 3a95d7d0983af26811e72d238d94f11c25f1851a
URL: https://github.com/llvm/llvm-project/commit/3a95d7d0983af26811e72d238d94f11c25f1851a
DIFF: https://github.com/llvm/llvm-project/commit/3a95d7d0983af26811e72d238d94f11c25f1851a.diff
LOG: [clang] Fix -fp-model={strict|precise} to disable -fapprox-func
`-fapprox-func` should be disabled by `-fp-model={strict|precise}`,
as well as other fast-math flags. See the last changes in
`clang/test/Driver/fp-model.c`.
Probably this route (`case options::OPT_ffp_model_EQ`) was forgot
to update in D106191 and D114564. There is no appropriate reason not
to disable the flag.
This commit also updates other regression tests, which are not directly
related to this bug, for consistency with other fast-math flags.
Differential Revision: https://reviews.llvm.org/D138109
Added:
Modified:
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CodeGen/fp-options-to-fast-math-flags.c
clang/test/Driver/fast-math.c
clang/test/Driver/fp-model.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 3833fb4b0bafd..fcf99c88d4c2c 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2808,6 +2808,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
// If -ffp-model= is seen, reset to fno-fast-math
HonorINFs = true;
HonorNaNs = true;
+ ApproxFunc = false;
// Turning *off* -ffast-math restores the toolchain default.
MathErrno = TC.IsMathErrnoDefault();
AssociativeMath = false;
diff --git a/clang/test/CodeGen/fp-options-to-fast-math-flags.c b/clang/test/CodeGen/fp-options-to-fast-math-flags.c
index bd44eb3874048..d7fcc586fed4b 100644
--- a/clang/test/CodeGen/fp-options-to-fast-math-flags.c
+++ b/clang/test/CodeGen/fp-options-to-fast-math-flags.c
@@ -5,6 +5,7 @@
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fno-signed-zeros -emit-llvm -o - %s | FileCheck -check-prefix CHECK-NO-SIGNED-ZEROS %s
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -mreassociate -emit-llvm -o - %s | FileCheck -check-prefix CHECK-REASSOC %s
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -freciprocal-math -emit-llvm -o - %s | FileCheck -check-prefix CHECK-RECIP %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fapprox-func -emit-llvm -o - %s | FileCheck -check-prefix CHECK-AFN %s
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -funsafe-math-optimizations -emit-llvm -o - %s | FileCheck -check-prefix CHECK-UNSAFE %s
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ffast-math -emit-llvm -o - %s | FileCheck -check-prefix CHECK-FAST %s
@@ -35,6 +36,9 @@ float test(float a) {
// CHECK-RECIP: [[CALL_RES:%.+]] = call arcp float @fn(float noundef {{%.+}})
// CHECK-RECIP: {{%.+}} = fadd arcp float {{%.+}}, [[CALL_RES]]
+// CHECK-AFN: [[CALL_RES:%.+]] = call afn float @fn(float noundef {{%.+}})
+// CHECK-AFN: {{%.+}} = fadd afn float {{%.+}}, [[CALL_RES]]
+
// CHECK-UNSAFE: [[CALL_RES:%.+]] = call reassoc nsz arcp afn float @fn(float noundef {{%.+}})
// CHECK-UNSAFE: {{%.+}} = fadd reassoc nsz arcp afn float {{%.+}}, [[CALL_RES]]
diff --git a/clang/test/Driver/fast-math.c b/clang/test/Driver/fast-math.c
index 869c85650465e..fd21ef7913ded 100644
--- a/clang/test/Driver/fast-math.c
+++ b/clang/test/Driver/fast-math.c
@@ -91,6 +91,16 @@
// CHECK-APPROX-FUNC: "-cc1"
// CHECK-APPROX-FUNC: "-fapprox-func"
//
+// RUN: %clang -### -fno-fast-math -fapprox-func -c %s 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-NO-FAST-MATH-APPROX-FUNC %s
+// CHECK-NO-FAST-MATH-APPROX-FUNC: "-cc1"
+// CHECK-NO-FAST-MATH-APPROX-FUNC: "-fapprox-func"
+//
+// RUN: %clang -### -fapprox-func -fno-fast-math -c %s 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-APPROX-FUNC-NO-FAST-MATH %s
+// CHECK-APPROX-FUNC-NO-FAST-MATH: "-cc1"
+// CHECK-APPROX-FUNC-NO-FAST-MATH-NOT: "-fapprox-func"
+//
// RUN: %clang -### -fmath-errno -c %s 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-MATH-ERRNO %s
// CHECK-MATH-ERRNO: "-cc1"
diff --git a/clang/test/Driver/fp-model.c b/clang/test/Driver/fp-model.c
index 4253cf7a50f20..28410afa595ae 100644
--- a/clang/test/Driver/fp-model.c
+++ b/clang/test/Driver/fp-model.c
@@ -77,6 +77,10 @@
// RUN: --check-prefix=WARN12 %s
// WARN12-NOT: warning: overriding '-ffp-model=strict' option with '-ffp-model=strict' [-Woverriding-t-option]
+// RUN: %clang -### -ffp-model=strict -fapprox-func -c %s 2>&1 \
+// RUN: | FileCheck --check-prefix=WARN13 %s
+// WARN13: warning: overriding '-ffp-model=strict' option with '-fapprox-func' [-Woverriding-t-option]
+
// RUN: %clang -### -c %s 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-NOROUND %s
// CHECK-NOROUND: "-cc1"
@@ -97,6 +101,7 @@
// CHECK-FPM-FAST: "-cc1"
// CHECK-FPM-FAST: "-menable-no-infs"
// CHECK-FPM-FAST: "-menable-no-nans"
+// CHECK-FPM-FAST: "-fapprox-func"
// CHECK-FPM-FAST: "-funsafe-math-optimizations"
// CHECK-FPM-FAST: "-fno-signed-zeros"
// CHECK-FPM-FAST: "-mreassociate"
@@ -144,3 +149,47 @@
// CHECK-FEB-IGNORE: "-fno-rounding-math"
// CHECK-FEB-IGNORE: "-ffp-exception-behavior=ignore"
+// RUN: %clang -### -nostdinc -ffast-math -ffp-model=fast -c %s 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-FASTMATH-FPM-FAST %s
+// CHECK-FASTMATH-FPM-FAST: "-cc1"
+// CHECK-FASTMATH-FPM-FAST: "-menable-no-infs"
+// CHECK-FASTMATH-FPM-FAST: "-menable-no-nans"
+// CHECK-FASTMATH-FPM-FAST: "-fapprox-func"
+// CHECK-FASTMATH-FPM-FAST: "-funsafe-math-optimizations"
+// CHECK-FASTMATH-FPM-FAST: "-fno-signed-zeros"
+// CHECK-FASTMATH-FPM-FAST: "-mreassociate"
+// CHECK-FASTMATH-FPM-FAST: "-freciprocal-math"
+// CHECK-FASTMATH-FPM-FAST: "-ffp-contract=fast"
+// CHECK-FASTMATH-FPM-FAST: "-fno-rounding-math"
+// CHECK-FASTMATH-FPM-FAST: "-ffast-math"
+// CHECK-FASTMATH-FPM-FAST: "-ffinite-math-only"
+
+// RUN: %clang -### -nostdinc -ffast-math -ffp-model=precise -c %s 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-FASTMATH-FPM-PRECISE %s
+// CHECK-FASTMATH-FPM-PRECISE: "-cc1"
+// CHECK-FASTMATH-FPM-PRECISE-NOT: "-menable-no-infs"
+// CHECK-FASTMATH-FPM-PRECISE-NOT: "-menable-no-nans"
+// CHECK-FASTMATH-FPM-PRECISE-NOT: "-fapprox-func"
+// CHECK-FASTMATH-FPM-PRECISE-NOT: "-funsafe-math-optimizations"
+// CHECK-FASTMATH-FPM-PRECISE-NOT: "-fno-signed-zeros"
+// CHECK-FASTMATH-FPM-PRECISE-NOT: "-mreassociate"
+// CHECK-FASTMATH-FPM-PRECISE-NOT: "-freciprocal-math"
+// CHECK-FASTMATH-FPM-PRECISE: "-ffp-contract=on"
+// CHECK-FASTMATH-FPM-PRECISE: "-fno-rounding-math"
+// CHECK-FASTMATH-FPM-PRECISE-NOT: "-ffast-math"
+// CHECK-FASTMATH-FPM-PRECISE-NOT: "-ffinite-math-only"
+
+// RUN: %clang -### -nostdinc -ffast-math -ffp-model=strict -c %s 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-FASTMATH-FPM-STRICT %s
+// CHECK-FASTMATH-FPM-STRICT: "-cc1"
+// CHECK-FASTMATH-FPM-STRICT-NOT: "-menable-no-infs"
+// CHECK-FASTMATH-FPM-STRICT-NOT: "-menable-no-nans"
+// CHECK-FASTMATH-FPM-STRICT-NOT: "-fapprox-func"
+// CHECK-FASTMATH-FPM-STRICT-NOT: "-funsafe-math-optimizations"
+// CHECK-FASTMATH-FPM-STRICT-NOT: "-fno-signed-zeros"
+// CHECK-FASTMATH-FPM-STRICT-NOT: "-mreassociate"
+// CHECK-FASTMATH-FPM-STRICT-NOT: "-freciprocal-math"
+// CHECK-FASTMATH-FPM-STRICT: "-ffp-contract=off"
+// CHECK-FASTMATH-FPM-STRICT-NOT: "-fno-rounding-math"
+// CHECK-FASTMATH-FPM-STRICT-NOT: "-ffast-math"
+// CHECK-FASTMATH-FPM-STRICT-NOT: "-ffinite-math-only"
More information about the cfe-commits
mailing list