Skip to content

Commit 8ab931c

Browse files
author
Andy Kaylor
committed
Clean up denormal handling with -ffp-model, -ffast-math, etc.
This change cleans up the clang driver handling of umbrella options like -ffast-math, -funsafe-math-optimizations, and -ffp-model, and aligns the behavior of -ffp-model=fast with -ffast-math with regard to the linking of crtfastmath.o. We agreed in a previous review that the fast-math options should not attempt to change the -fdenormal-fp-math option, which is inherently target-specific. The clang user's manual claims that -ffp-model=fast "behaves identically to specifying both -ffast-math and -ffp-contract=fast." Since -ffast-math causes crtfastmath.o to be linked if it is available, that should also happen with -ffp-model=fast. I am going to be proposing further changes to -ffp-model=fast, decoupling it from -ffast-math and introducing a new -ffp-model=aggressive that matches the current behavior, but I wanted to solidfy the current behavior before I do that.
1 parent 02660e2 commit 8ab931c

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

clang/docs/UsersManual.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,8 +1452,8 @@ floating point semantic models: precise (the default), strict, and fast.
14521452
"fenv_access", "off", "on", "off"
14531453
"rounding_mode", "tonearest", "dynamic", "tonearest"
14541454
"contract", "on", "off", "fast"
1455-
"denormal_fp_math", "IEEE", "IEEE", "IEEE"
1456-
"denormal_fp32_math", "IEEE","IEEE", "IEEE"
1455+
"denormal_fp_math", "IEEE", "IEEE", "target-dependent"
1456+
"denormal_fp32_math", "IEEE","IEEE", "target-dependent"
14571457
"support_math_errno", "on", "on", "off"
14581458
"no_honor_nans", "off", "off", "on"
14591459
"no_honor_infinities", "off", "off", "on"

clang/lib/Driver/ToolChain.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1319,11 +1319,17 @@ bool ToolChain::isFastMathRuntimeAvailable(const ArgList &Args,
13191319
Arg *A =
13201320
Args.getLastArg(options::OPT_ffast_math, options::OPT_fno_fast_math,
13211321
options::OPT_funsafe_math_optimizations,
1322-
options::OPT_fno_unsafe_math_optimizations);
1322+
options::OPT_fno_unsafe_math_optimizations,
1323+
options::OPT_ffp_model_EQ);
13231324

13241325
if (!A || A->getOption().getID() == options::OPT_fno_fast_math ||
13251326
A->getOption().getID() == options::OPT_fno_unsafe_math_optimizations)
13261327
Default = false;
1328+
if (A && A->getOption().getID() == options::OPT_ffp_model_EQ) {
1329+
StringRef Model = A->getValue();
1330+
if (Model != "fast")
1331+
Default = false;
1332+
}
13271333
}
13281334

13291335
// Whatever decision came as a result of the above implicit settings, either

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,6 +2924,10 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
29242924
if (Val.equals("fast")) {
29252925
FPModel = Val;
29262926
applyFastMath();
2927+
// The target-specific getDefaultDenormalModeForType handler should
2928+
// account for -ffp-model=fast and choose its behavior
2929+
DenormalFPMath = DefaultDenormalFPMath;
2930+
DenormalFP32Math = DefaultDenormalFP32Math;
29272931
} else if (Val.equals("precise")) {
29282932
optID = options::OPT_ffp_contract;
29292933
FPModel = Val;

clang/test/Driver/linux-ld.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,9 @@
14171417
// RUN: %clang --target=x86_64-unknown-linux -no-pie -### %s -funsafe-math-optimizations\
14181418
// RUN: --sysroot=%S/Inputs/basic_linux_tree 2>&1 \
14191419
// RUN: | FileCheck --check-prefix=CHECK-CRTFASTMATH %s
1420+
// RUN: %clang --target=x86_64-unknown-linux -no-pie -### %s -ffp-model=fast \
1421+
// RUN: --sysroot=%S/Inputs/basic_linux_tree 2>&1 \
1422+
// RUN: | FileCheck --check-prefix=CHECK-CRTFASTMATH %s
14201423
// RUN: %clang --target=x86_64-unknown-linux -no-pie -### %s -Ofast\
14211424
// RUN: --sysroot=%S/Inputs/basic_linux_tree 2>&1 \
14221425
// RUN: | FileCheck --check-prefix=CHECK-CRTFASTMATH %s

clang/test/Driver/solaris-ld.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@
193193
// RUN: %clang --target=sparc-sun-solaris2.11 -### %s -ffast-math \
194194
// RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
195195
// RUN: | FileCheck --check-prefix=CHECK-CRTFASTMATH-SPARC32 %s
196+
// RUN: %clang --target=sparc-sun-solaris2.11 -### %s -ffp-model=fast \
197+
// RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
198+
// RUN: | FileCheck --check-prefix=CHECK-CRTFASTMATH-SPARC32 %s
196199
// CHECK-CRTFASTMATH-SPARC32: "-isysroot" "[[SYSROOT:[^"]+]]"
197200
// CHECK-CRTFASTMATH-SPARC32: "[[SYSROOT]]/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2{{/|\\\\}}crtfastmath.o"
198201
// CHECK-NOCRTFASTMATH-SPARC32-NOT: crtfastmath.o

0 commit comments

Comments
 (0)