Skip to content

Commit 0a1123e

Browse files
committed
Reland D74436 "Change clang option -ffp-model=precise to select ffp-contract=on"
Buildbot are failing with the current revert status. So reland with a fix to fp-model.c
1 parent b23ec43 commit 0a1123e

File tree

5 files changed

+88
-49
lines changed

5 files changed

+88
-49
lines changed

clang/docs/UsersManual.rst

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,8 +1190,50 @@ installed.
11901190
Controlling Floating Point Behavior
11911191
-----------------------------------
11921192

1193-
Clang provides a number of ways to control floating point behavior. The options
1194-
are listed below.
1193+
Clang provides a number of ways to control floating point behavior, including
1194+
with command line options and source pragmas. This section
1195+
describes the various floating point semantic modes and the corresponding options.
1196+
1197+
.. csv-table:: Floating Point Semantic Modes
1198+
:header: "Mode", "Values"
1199+
:widths: 15, 30, 30
1200+
1201+
"except_behavior", "{ignore, strict, may_trap}", "ffp-exception-behavior"
1202+
"fenv_access", "{off, on}", "(none)"
1203+
"rounding_mode", "{dynamic, tonearest, downward, upward, towardzero}", "frounding-math"
1204+
"contract", "{on, off, fast}", "ffp-contract"
1205+
"denormal_fp_math", "{IEEE, PreserveSign, PositiveZero}", "fdenormal-fp-math"
1206+
"denormal_fp32_math", "{IEEE, PreserveSign, PositiveZero}", "fdenormal-fp-math-fp32"
1207+
"support_math_errno", "{on, off}", "fmath-errno"
1208+
"no_honor_nans", "{on, off}", "fhonor-nans"
1209+
"no_honor_infinities", "{on, off}", "fhonor-infinities"
1210+
"no_signed_zeros", "{on, off}", "fsigned-zeros"
1211+
"allow_reciprocal", "{on, off}", "freciprocal-math"
1212+
"allow_approximate_fns", "{on, off}", "(none)"
1213+
"allow_reassociation", "{on, off}", "fassociative-math"
1214+
1215+
1216+
This table describes the option settings that correspond to the three
1217+
floating point semantic models: precise (the default), strict, and fast.
1218+
1219+
1220+
.. csv-table:: Floating Point Models
1221+
:header: "Mode", "Precise", "Strict", "Fast"
1222+
:widths: 25, 15, 15, 15
1223+
1224+
"except_behavior", "ignore", "strict", "ignore"
1225+
"fenv_access", "off", "on", "off"
1226+
"rounding_mode", "tonearest", "dynamic", "tonearest"
1227+
"contract", "on", "off", "fast"
1228+
"denormal_fp_math", "IEEE", "IEEE", "PreserveSign"
1229+
"denormal_fp32_math", "IEEE","IEEE", "PreserveSign"
1230+
"support_math_errno", "on", "on", "off"
1231+
"no_honor_nans", "off", "off", "on"
1232+
"no_honor_infinities", "off", "off", "on"
1233+
"no_signed_zeros", "off", "off", "on"
1234+
"allow_reciprocal", "off", "off", "on"
1235+
"allow_approximate_fns", "off", "off", "on"
1236+
"allow_reassociation", "off", "off", "on"
11951237

11961238
.. option:: -ffast-math
11971239

@@ -1385,7 +1427,7 @@ Note that floating-point operations performed as part of constant initialization
13851427
and ``fast``.
13861428
Details:
13871429

1388-
* ``precise`` Disables optimizations that are not value-safe on floating-point data, although FP contraction (FMA) is enabled (``-ffp-contract=fast``). This is the default behavior.
1430+
* ``precise`` Disables optimizations that are not value-safe on floating-point data, although FP contraction (FMA) is enabled (``-ffp-contract=on``). This is the default behavior.
13891431
* ``strict`` Enables ``-frounding-math`` and ``-ffp-exception-behavior=strict``, and disables contractions (FMA). All of the ``-ffast-math`` enablements are disabled.
13901432
* ``fast`` Behaves identically to specifying both ``-ffast-math`` and ``ffp-contract=fast``
13911433

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2525,10 +2525,9 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
25252525

25262526
llvm::DenormalMode DenormalFPMath = DefaultDenormalFPMath;
25272527
llvm::DenormalMode DenormalFP32Math = DefaultDenormalFP32Math;
2528-
StringRef FPContract = "";
2528+
StringRef FPContract = "on";
25292529
bool StrictFPModel = false;
25302530

2531-
25322531
if (const Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) {
25332532
CmdArgs.push_back("-mlimit-float-precision");
25342533
CmdArgs.push_back(A->getValue());
@@ -2551,7 +2550,6 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
25512550
SignedZeros = true;
25522551
// -fno_fast_math restores default denormal and fpcontract handling
25532552
DenormalFPMath = DefaultDenormalFPMath;
2554-
FPContract = "";
25552553
StringRef Val = A->getValue();
25562554
if (OFastEnabled && !Val.equals("fast")) {
25572555
// Only -ffp-model=fast is compatible with OFast, ignore.
@@ -2565,26 +2563,25 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
25652563
// ffp-model= is a Driver option, it is entirely rewritten into more
25662564
// granular options before being passed into cc1.
25672565
// Use the gcc option in the switch below.
2568-
if (!FPModel.empty() && !FPModel.equals(Val)) {
2566+
if (!FPModel.empty() && !FPModel.equals(Val))
25692567
D.Diag(clang::diag::warn_drv_overriding_flag_option)
25702568
<< Args.MakeArgString("-ffp-model=" + FPModel)
25712569
<< Args.MakeArgString("-ffp-model=" + Val);
2572-
FPContract = "";
2573-
}
25742570
if (Val.equals("fast")) {
25752571
optID = options::OPT_ffast_math;
25762572
FPModel = Val;
25772573
FPContract = "fast";
25782574
} else if (Val.equals("precise")) {
25792575
optID = options::OPT_ffp_contract;
25802576
FPModel = Val;
2581-
FPContract = "fast";
2577+
FPContract = "on";
25822578
PreciseFPModel = true;
25832579
} else if (Val.equals("strict")) {
25842580
StrictFPModel = true;
25852581
optID = options::OPT_frounding_math;
25862582
FPExceptionBehavior = "strict";
25872583
FPModel = Val;
2584+
FPContract = "off";
25882585
TrappingMath = true;
25892586
} else
25902587
D.Diag(diag::err_drv_unsupported_option_argument)
@@ -2663,9 +2660,11 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
26632660
case options::OPT_ffp_contract: {
26642661
StringRef Val = A->getValue();
26652662
if (PreciseFPModel) {
2666-
// -ffp-model=precise enables ffp-contract=fast as a side effect
2667-
// the FPContract value has already been set to a string literal
2668-
// and the Val string isn't a pertinent value.
2663+
// When -ffp-model=precise is seen on the command line,
2664+
// the boolean PreciseFPModel is set to true which indicates
2665+
// "the current option is actually PreciseFPModel". The optID
2666+
// is changed to OPT_ffp_contract and FPContract is set to "on".
2667+
// the argument Val string is "precise": it shouldn't be checked.
26692668
;
26702669
} else if (Val.equals("fast") || Val.equals("on") || Val.equals("off"))
26712670
FPContract = Val;
@@ -2762,7 +2761,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
27622761
// -fno_fast_math restores default denormal and fpcontract handling
27632762
DenormalFPMath = DefaultDenormalFPMath;
27642763
DenormalFP32Math = DefaultDenormalFP32Math;
2765-
FPContract = "";
2764+
FPContract = "on";
27662765
break;
27672766
}
27682767
if (StrictFPModel) {

clang/test/CodeGen/ppc-emmintrin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// REQUIRES: powerpc-registered-target
33

44
// RUN: %clang -S -emit-llvm -target powerpc64-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
5-
// RUN: -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
5+
// RUN: -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
66
// RUN: %clang -S -emit-llvm -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
7-
// RUN: -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-LE
7+
// RUN: -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-LE
88

99
// CHECK-BE-DAG: @_mm_movemask_pd.perm_mask = internal constant <4 x i32> <i32 -2139062144, i32 -2139062144, i32 -2139062144, i32 -2139078656>, align 16
1010
// CHECK-BE-DAG: @_mm_shuffle_epi32.permute_selectors = internal constant [4 x i32] [i32 66051, i32 67438087, i32 134810123, i32 202182159], align 4

clang/test/CodeGen/ppc-xmmintrin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// REQUIRES: powerpc-registered-target
33

44
// RUN: %clang -S -emit-llvm -target powerpc64-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
5-
// RUN: -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
5+
// RUN: -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
66
// RUN: %clang -S -emit-llvm -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
7-
// RUN: -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-LE
7+
// RUN: -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-LE
88

99
#include <xmmintrin.h>
1010

clang/test/Driver/fp-model.c

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,87 @@
11
// Test that incompatible combinations of -ffp-model= options
22
// and other floating point options get a warning diagnostic.
3-
//
4-
// REQUIRES: clang-driver
53

6-
// RUN: %clang -### -ffp-model=fast -ffp-contract=off -c %s 2>&1 \
4+
// RUN: %clang -target x86_64 -### -ffp-model=fast -ffp-contract=off -c %s 2>&1 \
75
// RUN: | FileCheck --check-prefix=WARN %s
86
// WARN: warning: overriding '-ffp-model=fast' option with '-ffp-contract=off' [-Woverriding-t-option]
97

10-
// RUN: %clang -### -ffp-model=fast -ffp-contract=on -c %s 2>&1 \
8+
// RUN: %clang -target x86_64 -### -ffp-model=fast -ffp-contract=on -c %s 2>&1 \
119
// RUN: | FileCheck --check-prefix=WARN1 %s
1210
// WARN1: warning: overriding '-ffp-model=fast' option with '-ffp-contract=on' [-Woverriding-t-option]
1311

14-
// RUN: %clang -### -ffp-model=strict -fassociative-math -c %s 2>&1 \
12+
// RUN: %clang -target x86_64 -### -ffp-model=strict -fassociative-math -c %s 2>&1 \
1513
// RUN: | FileCheck --check-prefix=WARN2 %s
1614
// WARN2: warning: overriding '-ffp-model=strict' option with '-fassociative-math' [-Woverriding-t-option]
1715

18-
// RUN: %clang -### -ffp-model=strict -ffast-math -c %s 2>&1 \
16+
// RUN: %clang -target x86_64 -### -ffp-model=strict -ffast-math -c %s 2>&1 \
1917
// RUN: | FileCheck --check-prefix=WARN3 %s
2018
// WARN3: warning: overriding '-ffp-model=strict' option with '-ffast-math' [-Woverriding-t-option]
2119

22-
// RUN: %clang -### -ffp-model=strict -ffinite-math-only -c %s 2>&1 \
20+
// RUN: %clang -target x86_64 -### -ffp-model=strict -ffinite-math-only -c %s 2>&1 \
2321
// RUN: | FileCheck --check-prefix=WARN4 %s
2422
// WARN4: warning: overriding '-ffp-model=strict' option with '-ffinite-math-only' [-Woverriding-t-option]
2523

26-
// RUN: %clang -### -ffp-model=strict -ffp-contract=fast -c %s 2>&1 \
24+
// RUN: %clang -target x86_64 -### -ffp-model=strict -ffp-contract=fast -c %s 2>&1 \
2725
// RUN: | FileCheck --check-prefix=WARN5 %s
2826
// WARN5: warning: overriding '-ffp-model=strict' option with '-ffp-contract=fast' [-Woverriding-t-option]
2927

30-
// RUN: %clang -### -ffp-model=strict -ffp-contract=off -c %s 2>&1 \
28+
// RUN: %clang -target x86_64 -### -ffp-model=strict -ffp-contract=fast -c %s 2>&1 \
3129
// RUN: | FileCheck --check-prefix=WARN6 %s
32-
// WARN6: warning: overriding '-ffp-model=strict' option with '-ffp-contract=off' [-Woverriding-t-option]
30+
// WARN6: warning: overriding '-ffp-model=strict' option with '-ffp-contract=fast' [-Woverriding-t-option]
3331

34-
// RUN: %clang -### -ffp-model=strict -ffp-contract=on -c %s 2>&1 \
32+
// RUN: %clang -target x86_64 -### -ffp-model=strict -ffp-contract=on -c %s 2>&1 \
3533
// RUN: | FileCheck --check-prefix=WARN7 %s
3634
// WARN7: warning: overriding '-ffp-model=strict' option with '-ffp-contract=on' [-Woverriding-t-option]
3735

38-
// RUN: %clang -### -ffp-model=strict -fno-honor-infinities -c %s 2>&1 \
36+
// RUN: %clang -target x86_64 -### -ffp-model=strict -fno-honor-infinities -c %s 2>&1 \
3937
// RUN: | FileCheck --check-prefix=WARN8 %s
4038
// WARN8: warning: overriding '-ffp-model=strict' option with '-fno-honor-infinities' [-Woverriding-t-option]
4139

42-
// RUN: %clang -### -ffp-model=strict -fno-honor-nans -c %s 2>&1 \
40+
// RUN: %clang -target x86_64 -### -ffp-model=strict -fno-honor-nans -c %s 2>&1 \
4341
// RUN: | FileCheck --check-prefix=WARN9 %s
4442
// WARN9: warning: overriding '-ffp-model=strict' option with '-fno-honor-nans' [-Woverriding-t-option]
4543

46-
// RUN: %clang -### -ffp-model=strict -fno-rounding-math -c %s 2>&1 \
44+
// RUN: %clang -target x86_64 -### -ffp-model=strict -fno-rounding-math -c %s 2>&1 \
4745
// RUN: | FileCheck --check-prefix=WARNa %s
4846
// WARNa: warning: overriding '-ffp-model=strict' option with '-fno-rounding-math' [-Woverriding-t-option]
4947

50-
// RUN: %clang -### -ffp-model=strict -fno-signed-zeros -c %s 2>&1 \
48+
// RUN: %clang -target x86_64 -### -ffp-model=strict -fno-signed-zeros -c %s 2>&1 \
5149
// RUN: | FileCheck --check-prefix=WARNb %s
5250
// WARNb: warning: overriding '-ffp-model=strict' option with '-fno-signed-zeros' [-Woverriding-t-option]
5351

54-
// RUN: %clang -### -ffp-model=strict -fno-trapping-math -c %s 2>&1 \
52+
// RUN: %clang -target x86_64 -### -ffp-model=strict -fno-trapping-math -c %s 2>&1 \
5553
// RUN: | FileCheck --check-prefix=WARNc %s
5654
// WARNc: warning: overriding '-ffp-model=strict' option with '-fno-trapping-math' [-Woverriding-t-option]
5755

58-
// RUN: %clang -### -ffp-model=strict -freciprocal-math -c %s 2>&1 \
56+
// RUN: %clang -target x86_64 -### -ffp-model=strict -freciprocal-math -c %s 2>&1 \
5957
// RUN: | FileCheck --check-prefix=WARNd %s
6058
// WARNd: warning: overriding '-ffp-model=strict' option with '-freciprocal-math' [-Woverriding-t-option]
6159

62-
// RUN: %clang -### -ffp-model=strict -funsafe-math-optimizations -c %s 2>&1 \
60+
// RUN: %clang -target x86_64 -### -ffp-model=strict -funsafe-math-optimizations -c %s 2>&1 \
6361
// RUN: | FileCheck --check-prefix=WARNe %s
6462
// WARNe: warning: overriding '-ffp-model=strict' option with '-funsafe-math-optimizations' [-Woverriding-t-option]
6563

66-
// RUN: %clang -### -ffp-model=strict -Ofast -c %s 2>&1 \
64+
// RUN: %clang -target x86_64 -### -ffp-model=strict -Ofast -c %s 2>&1 \
6765
// RUN: | FileCheck --check-prefix=WARNf %s
6866
// WARNf: warning: overriding '-ffp-model=strict' option with '-Ofast' [-Woverriding-t-option]
6967

70-
// RUN: %clang -### -c %s 2>&1 \
68+
// RUN: %clang -target x86_64 -### -c %s 2>&1 \
7169
// RUN: | FileCheck --check-prefix=CHECK-NOROUND %s
7270
// CHECK-NOROUND: "-cc1"
7371
// CHECK-NOROUND: "-fno-rounding-math"
7472

75-
// RUN: %clang -### -frounding-math -c %s 2>&1 \
73+
// RUN: %clang -target x86_64 -### -frounding-math -c %s 2>&1 \
7674
// RUN: | FileCheck --check-prefix=CHECK-ROUND --implicit-check-not ffp-exception-behavior=strict %s
7775
// CHECK-ROUND: "-cc1"
7876
// CHECK-ROUND: "-frounding-math"
7977

80-
// RUN: %clang -### -ftrapping-math -c %s 2>&1 \
78+
// RUN: %clang -target x86_64 -### -ftrapping-math -c %s 2>&1 \
8179
// RUN: | FileCheck --check-prefix=CHECK-TRAP %s
8280
// CHECK-TRAP: "-cc1"
8381
// CHECK-TRAP: "-ftrapping-math"
8482
// CHECK-TRAP: "-ffp-exception-behavior=strict"
8583

86-
// RUN: %clang -### -nostdinc -ffp-model=fast -c %s 2>&1 \
84+
// RUN: %clang -target x86_64 -### -nostdinc -ffp-model=fast -c %s 2>&1 \
8785
// RUN: | FileCheck --check-prefix=CHECK-FPM-FAST %s
8886
// CHECK-FPM-FAST: "-cc1"
8987
// CHECK-FPM-FAST: "-menable-no-infs"
@@ -97,41 +95,41 @@
9795
// CHECK-FPM-FAST: "-ffast-math"
9896
// CHECK-FPM-FAST: "-ffinite-math-only"
9997

100-
// RUN: %clang -### -nostdinc -ffp-model=precise -c %s 2>&1 \
98+
// RUN: %clang -target x86_64 -### -nostdinc -ffp-model=precise -c %s 2>&1 \
10199
// RUN: | FileCheck --check-prefix=CHECK-FPM-PRECISE %s
102100
// CHECK-FPM-PRECISE: "-cc1"
103-
// CHECK-FPM-PRECISE: "-ffp-contract=fast"
101+
// CHECK-FPM-PRECISE: "-ffp-contract=on"
104102
// CHECK-FPM-PRECISE: "-fno-rounding-math"
105103

106-
// RUN: %clang -### -nostdinc -ffp-model=strict -c %s 2>&1 \
104+
// RUN: %clang -target x86_64 -### -nostdinc -ffp-model=strict -c %s 2>&1 \
107105
// RUN: | FileCheck --check-prefix=CHECK-FPM-STRICT %s
108106
// CHECK-FPM-STRICT: "-cc1"
109107
// CHECK-FPM-STRICT: "-ftrapping-math"
108+
// CHECK-FPM-STRICT: "-ffp-contract=off"
110109
// CHECK-FPM-STRICT: "-frounding-math"
111110
// CHECK-FPM-STRICT: "-ffp-exception-behavior=strict"
112111

113-
// RUN: %clang -### -nostdinc -ftrapping-math -ffp-exception-behavior=ignore -c %s 2>&1 \
112+
// RUN: %clang -target x86_64 -### -nostdinc -ftrapping-math -ffp-exception-behavior=ignore -c %s 2>&1 \
114113
// RUN: | FileCheck --check-prefix=CHECK-TRAP-IGNORE %s
115114
// CHECK-TRAP-IGNORE: "-cc1"
116115
// CHECK-TRAP-IGNORE: "-fno-rounding-math"
117116
// CHECK-TRAP-IGNORE: "-ffp-exception-behavior=ignore"
118117

119118

120-
// RUN: %clang -### -nostdinc -ffp-exception-behavior=strict -c %s 2>&1 \
119+
// RUN: %clang -target x86_64 -### -nostdinc -ffp-exception-behavior=strict -c %s 2>&1 \
121120
// RUN: | FileCheck --check-prefix=CHECK-FEB-STRICT %s
122121
// CHECK-FEB-STRICT: "-cc1"
123122
// CHECK-FEB-STRICT: "-fno-rounding-math"
124123
// CHECK-FEB-STRICT: "-ffp-exception-behavior=strict"
125124

126-
// RUN: %clang -### -nostdinc -ffp-exception-behavior=maytrap -c %s 2>&1 \
125+
// RUN: %clang -target x86_64 -### -nostdinc -ffp-exception-behavior=maytrap -c %s 2>&1 \
127126
// RUN: | FileCheck --check-prefix=CHECK-FEB-MAYTRAP %s
128127
// CHECK-FEB-MAYTRAP: "-cc1"
129128
// CHECK-FEB-MAYTRAP: "-fno-rounding-math"
130129
// CHECK-FEB-MAYTRAP: "-ffp-exception-behavior=maytrap"
131130

132-
// RUN: %clang -### -nostdinc -ffp-exception-behavior=ignore -c %s 2>&1 \
131+
// RUN: %clang -target x86_64 -### -nostdinc -ffp-exception-behavior=ignore -c %s 2>&1 \
133132
// RUN: | FileCheck --check-prefix=CHECK-FEB-IGNORE %s
134133
// CHECK-FEB-IGNORE: "-cc1"
135134
// CHECK-FEB-IGNORE: "-fno-rounding-math"
136135
// CHECK-FEB-IGNORE: "-ffp-exception-behavior=ignore"
137-

0 commit comments

Comments
 (0)