Skip to content

Commit b74e46c

Browse files
author
Andy Kaylor
committed
Apply complex range changes to all models and address review comments
1 parent 9ee59aa commit b74e46c

File tree

4 files changed

+82
-40
lines changed

4 files changed

+82
-40
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,12 @@ Modified Compiler Flags
178178

179179
- The ``-ffp-model`` option has been updated to enable a more limited set of
180180
optimizations when the ``fast`` argument is used and to accept a new argument,
181-
``aggressive``. The behavior of ``-ffp-model=aggressive`` is mostly equivalent
181+
``aggressive``. The behavior of ``-ffp-model=aggressive`` is equivalent
182182
to the previous behavior of ``-ffp-model=fast``. The updated
183-
``-ffp-model=fast`` behavior no longer assumes finite math only and uses a
183+
``-ffp-model=fast`` behavior no longer assumes finite math only, uses
184184
the ``promoted`` algorithm for complex division when possible rather than the
185-
less robust Smith algorithm. Both ``-ffp-model=fast`` and
186-
``-ffp-model=aggressive`` will now imply ``-ffp-contract=fast-honor-pragmas``
187-
rather than ``-ffp-contract=fast``.
185+
less basic (limited range) algorithm, and sets
186+
``-ffp-contract=fast-honor-pragmas`` rather than ``-ffp-contract=fast``.
188187

189188
Removed Compiler Flags
190189
-------------------------

clang/docs/UsersManual.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1770,7 +1770,7 @@ for more details.
17701770
top of the source file.
17711771
* ``fast`` Behaves identically to specifying ``-funsafe-math-optimizations``,
17721772
``-fno-math-errno`` and ``-fcomplex-arithmetic=promoted``
1773-
``ffp-contract=fast``
1773+
``ffp-contract=fast-honor-pragmas``
17741774
* ``aggressive`` Behaves identically to specifying both ``-ffast-math`` and
17751775
``ffp-contract=fast``
17761776

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2918,19 +2918,30 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
29182918
std::string ComplexRangeStr = "";
29192919
std::string GccRangeComplexOption = "";
29202920

2921+
auto setComplexRange = [&](LangOptions::ComplexRangeKind NewRange) {
2922+
// Warn if user expects to perform full implementation of complex
2923+
// multiplication or division in the presence of nan or ninf flags.
2924+
if (Range != NewRange)
2925+
EmitComplexRangeDiag(D,
2926+
!GccRangeComplexOption.empty()
2927+
? GccRangeComplexOption
2928+
: ComplexArithmeticStr(Range),
2929+
ComplexArithmeticStr(NewRange));
2930+
Range = NewRange;
2931+
};
2932+
29212933
// Lambda to set fast-math options. This is also used by -ffp-model=fast
29222934
auto applyFastMath = [&](bool Aggressive) {
2923-
LangOptions::ComplexRangeKind NewRange;
29242935
if (Aggressive) {
29252936
HonorINFs = false;
29262937
HonorNaNs = false;
29272938
FPContract = "fast";
2928-
NewRange = LangOptions::ComplexRangeKind::CX_Basic;
2939+
setComplexRange(LangOptions::ComplexRangeKind::CX_Basic);
29292940
} else {
29302941
HonorINFs = true;
29312942
HonorNaNs = true;
29322943
FPContract = "fast-honor-pragmas";
2933-
NewRange = LangOptions::ComplexRangeKind::CX_Promoted;
2944+
setComplexRange(LangOptions::ComplexRangeKind::CX_Promoted);
29342945
}
29352946
MathErrno = false;
29362947
AssociativeMath = true;
@@ -2940,16 +2951,6 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
29402951
TrappingMath = false;
29412952
RoundingFPMath = false;
29422953
FPExceptionBehavior = "";
2943-
// Warn if user expects to perform full implementation of complex
2944-
// multiplication or division in the presence of nan or ninf flags.
2945-
if (Range != NewRange)
2946-
EmitComplexRangeDiag(
2947-
D,
2948-
!GccRangeComplexOption.empty()
2949-
? GccRangeComplexOption
2950-
: ComplexArithmeticStr(Range),
2951-
ComplexArithmeticStr(NewRange));
2952-
Range = NewRange;
29532954
SeenUnsafeMathModeOption = true;
29542955
};
29552956

@@ -3078,7 +3079,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
30783079

30793080
StringRef Val = A->getValue();
30803081
if (OFastEnabled && Val != "aggressive") {
3081-
// Only -ffp-model=aggressive is compatible with OFast, ignore.
3082+
// Only -ffp-model=aggressive is compatible with OFast, ignore.
30823083
D.Diag(clang::diag::warn_drv_overriding_option)
30833084
<< Args.MakeArgString("-ffp-model=" + Val) << "-Ofast";
30843085
break;
@@ -3093,15 +3094,16 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
30933094
applyFastMath(false);
30943095
// applyFastMath sets fp-contract="fast"
30953096
LastFpContractOverrideOption = "-ffp-model=fast";
3096-
} else if (Val.equals("aggressive")) {
3097+
} else if (Val == "aggressive") {
30973098
FPModel = Val;
30983099
applyFastMath(true);
30993100
// applyFastMath sets fp-contract="fast"
31003101
LastFpContractOverrideOption = "-ffp-model=aggressive";
3101-
} else if (Val.equals("precise")) {
3102+
} else if (Val == "precise") {
31023103
FPModel = Val;
31033104
FPContract = "on";
31043105
LastFpContractOverrideOption = "-ffp-model=precise";
3106+
setComplexRange(LangOptions::ComplexRangeKind::CX_Full);
31053107
} else if (Val == "strict") {
31063108
StrictFPModel = true;
31073109
FPExceptionBehavior = "strict";
@@ -3110,6 +3112,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
31103112
LastFpContractOverrideOption = "-ffp-model=strict";
31113113
TrappingMath = true;
31123114
RoundingFPMath = true;
3115+
setComplexRange(LangOptions::ComplexRangeKind::CX_Full);
31133116
} else
31143117
D.Diag(diag::err_drv_unsupported_option_argument)
31153118
<< A->getSpelling() << Val;

clang/test/Driver/fp-model.c

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
// RUN: %clang -### -ffp-model=aggressive -ffp-contract=off -c %s 2>&1 \
66
// RUN: | FileCheck --check-prefix=WARN %s
7-
// WARN: warning: overriding '-ffp-model=fast' option with '-ffp-contract=off' [-Woverriding-option]
7+
// WARN: warning: overriding '-ffp-model=aggressive' option with '-ffp-contract=off' [-Woverriding-option]
88

99
// RUN: %clang -### -ffp-model=aggressive -ffp-contract=on -c %s 2>&1 \
1010
// RUN: | FileCheck --check-prefix=WARN1 %s
11-
// WARN1: warning: overriding '-ffp-model=fast' option with '-ffp-contract=on' [-Woverriding-option]
11+
// WARN1: warning: overriding '-ffp-model=aggressive' option with '-ffp-contract=on' [-Woverriding-option]
1212

1313
// RUN: %clang -### -ffp-model=strict -fassociative-math -c %s 2>&1 \
1414
// RUN: | FileCheck --check-prefix=WARN2 %s
@@ -74,9 +74,12 @@
7474

7575
// RUN: %clang -### -Ofast -ffp-model=strict -c %s 2>&1 | FileCheck \
7676
// RUN: --check-prefix=WARN12 %s
77-
// RUN: %clang -### -Werror -ffast-math -ffp-model=strict -c %s
7877
// WARN12: warning: overriding '-ffp-model=strict' option with '-Ofast'
7978

79+
// RUN: %clang -### -ffast-math -ffp-model=strict -c %s 2>&1 | FileCheck \
80+
// RUN: --check-prefix=WARN-CX-BASIC-TO-FULL %s
81+
// WARN-CX-BASIC-TO-FULL: warning: overriding '-fcomplex-arithmetic=basic' option with '-fcomplex-arithmetic=full'
82+
8083
// RUN: %clang -### -ffp-model=strict -fapprox-func -c %s 2>&1 \
8184
// RUN: | FileCheck --check-prefix=WARN13 %s
8285
// WARN13: warning: overriding '-ffp-model=strict' option with '-fapprox-func' [-Woverriding-option]
@@ -109,20 +112,37 @@
109112
// CHECK-TRAP: "-cc1"
110113
// CHECK-TRAP: "-ffp-exception-behavior=strict"
111114

115+
// RUN: %clang -### -nostdinc -ffp-model=aggressive -c %s 2>&1 \
116+
// RUN: | FileCheck --check-prefix=CHECK-FPM-AGGR %s
117+
// CHECK-FPM-AGGR: "-cc1"
118+
// CHECK-FPM-AGGR: "-menable-no-infs"
119+
// CHECK-FPM-AGGR: "-menable-no-nans"
120+
// CHECK-FPM-AGGR: "-fapprox-func"
121+
// CHECK-FPM-AGGR: "-funsafe-math-optimizations"
122+
// CHECK-FPM-AGGR: "-fno-signed-zeros"
123+
// CHECK-FPM-AGGR: "-mreassociate"
124+
// CHECK-FPM-AGGR: "-freciprocal-math"
125+
// CHECK-FPM-AGGR: "-ffp-contract=fast"
126+
// CHECK-FPM-AGGR: "-fno-rounding-math"
127+
// CHECK-FPM-AGGR: "-ffast-math"
128+
// CHECK-FPM-AGGR: "-ffinite-math-only"
129+
// CHECK-FPM-AGGR: "-complex-range=basic"
130+
112131
// RUN: %clang -### -nostdinc -ffp-model=fast -c %s 2>&1 \
113132
// RUN: | FileCheck --check-prefix=CHECK-FPM-FAST %s
114133
// CHECK-FPM-FAST: "-cc1"
115-
// CHECK-FPM-FAST: "-menable-no-infs"
116-
// CHECK-FPM-FAST: "-menable-no-nans"
134+
// CHECK-FPM-FAST-NOT: "-menable-no-infs"
135+
// CHECK-FPM-FAST-NOT: "-menable-no-nans"
117136
// CHECK-FPM-FAST: "-fapprox-func"
118137
// CHECK-FPM-FAST: "-funsafe-math-optimizations"
119138
// CHECK-FPM-FAST: "-fno-signed-zeros"
120139
// CHECK-FPM-FAST: "-mreassociate"
121140
// CHECK-FPM-FAST: "-freciprocal-math"
122-
// CHECK-FPM-FAST: "-ffp-contract=fast"
141+
// CHECK-FPM-FAST: "-ffp-contract=fast-honor-pragmas"
123142
// CHECK-FPM-FAST: "-fno-rounding-math"
124-
// CHECK-FPM-FAST: "-ffast-math"
125-
// CHECK-FPM-FAST: "-ffinite-math-only"
143+
// CHECK-FPM-FAST-NOT: "-ffast-math"
144+
// CHECK-FPM-FAST-NOT: "-ffinite-math-only"
145+
// CHECK-FPM-FAST: "-complex-range=promoted"
126146

127147
// RUN: %clang -### -nostdinc -ffp-model=precise -c %s 2>&1 \
128148
// RUN: | FileCheck --check-prefix=CHECK-FPM-PRECISE %s
@@ -163,23 +183,41 @@
163183
// CHECK-FEB-IGNORE: "-fno-rounding-math"
164184
// CHECK-FEB-IGNORE: "-ffp-exception-behavior=ignore"
165185

166-
// RUN: %clang -### -nostdinc -Werror -ffast-math -ffp-model=fast -c %s 2>&1 \
186+
// RUN: %clang -### -nostdinc -Werror -ffast-math -ffp-model=aggressive -c %s 2>&1 \
187+
// RUN: | FileCheck --check-prefix=CHECK-FASTMATH-FPM-AGGR %s
188+
// CHECK-FASTMATH-FPM-AGGR: "-cc1"
189+
// CHECK-FASTMATH-FPM-AGGR: "-menable-no-infs"
190+
// CHECK-FASTMATH-FPM-AGGR: "-menable-no-nans"
191+
// CHECK-FASTMATH-FPM-AGGR: "-fapprox-func"
192+
// CHECK-FASTMATH-FPM-AGGR: "-funsafe-math-optimizations"
193+
// CHECK-FASTMATH-FPM-AGGR: "-fno-signed-zeros"
194+
// CHECK-FASTMATH-FPM-AGGR: "-mreassociate"
195+
// CHECK-FASTMATH-FPM-AGGR: "-freciprocal-math"
196+
// CHECK-FASTMATH-FPM-AGGR: "-ffp-contract=fast"
197+
// CHECK-FASTMATH-FPM-AGGR: "-fno-rounding-math"
198+
// CHECK-FASTMATH-FPM-AGGR: "-ffast-math"
199+
// CHECK-FASTMATH-FPM-AGGR: "-ffinite-math-only"
200+
// CHECK-FASTMATH-FPM-AGGR: "-complex-range=basic"
201+
202+
// RUN: %clang -### -nostdinc -ffast-math -ffp-model=fast -c %s 2>&1 \
167203
// RUN: | FileCheck --check-prefix=CHECK-FASTMATH-FPM-FAST %s
204+
// CHECK-FASTMATH-FPM-FAST: warning: overriding '-fcomplex-arithmetic=basic' option with '-fcomplex-arithmetic=promoted'
168205
// CHECK-FASTMATH-FPM-FAST: "-cc1"
169-
// CHECK-FASTMATH-FPM-FAST: "-menable-no-infs"
170-
// CHECK-FASTMATH-FPM-FAST: "-menable-no-nans"
206+
// CHECK-FASTMATH-FPM-FAST-NOT: "-menable-no-infs"
207+
// CHECK-FASTMATH-FPM-FAST-NOT: "-menable-no-nans"
171208
// CHECK-FASTMATH-FPM-FAST: "-fapprox-func"
172209
// CHECK-FASTMATH-FPM-FAST: "-funsafe-math-optimizations"
173210
// CHECK-FASTMATH-FPM-FAST: "-fno-signed-zeros"
174211
// CHECK-FASTMATH-FPM-FAST: "-mreassociate"
175212
// CHECK-FASTMATH-FPM-FAST: "-freciprocal-math"
176-
// CHECK-FASTMATH-FPM-FAST: "-ffp-contract=fast"
213+
// CHECK-FASTMATH-FPM-FAST: "-ffp-contract=fast-honor-pragmas"
177214
// CHECK-FASTMATH-FPM-FAST: "-fno-rounding-math"
178-
// CHECK-FASTMATH-FPM-FAST: "-ffast-math"
179-
// CHECK-FASTMATH-FPM-FAST: "-ffinite-math-only"
215+
// CHECK-FASTMATH-FPM-FAST-NOT: "-ffast-math"
216+
// CHECK-FASTMATH-FPM-FAST-NOT: "-ffinite-math-only"
217+
// CHECK-FASTMATH-FPM-FAST: "-complex-range=promoted"
180218

181-
// RUN: %clang -### -nostdinc -Werror -ffast-math -ffp-model=precise -c %s 2>&1 \
182-
// RUN: | FileCheck --check-prefix=CHECK-FASTMATH-FPM-PRECISE %s
219+
// RUN: %clang -### -nostdinc -ffast-math -ffp-model=precise -c %s 2>&1 \
220+
// RUN: | FileCheck --check-prefixes=CHECK-FASTMATH-FPM-PRECISE,WARN-CX-BASIC-TO-FULL %s
183221
// CHECK-FASTMATH-FPM-PRECISE: "-cc1"
184222
// CHECK-FASTMATH-FPM-PRECISE-NOT: "-menable-no-infs"
185223
// CHECK-FASTMATH-FPM-PRECISE-NOT: "-menable-no-nans"
@@ -192,9 +230,10 @@
192230
// CHECK-FASTMATH-FPM-PRECISE: "-fno-rounding-math"
193231
// CHECK-FASTMATH-FPM-PRECISE-NOT: "-ffast-math"
194232
// CHECK-FASTMATH-FPM-PRECISE-NOT: "-ffinite-math-only"
233+
// CHECK-FASTMATH-FPM-PRECISE: "-complex-range=full"
195234

196-
// RUN: %clang -### -nostdinc -Werror -ffast-math -ffp-model=strict -c %s 2>&1 \
197-
// RUN: | FileCheck --check-prefix=CHECK-FASTMATH-FPM-STRICT %s
235+
// RUN: %clang -### -nostdinc -ffast-math -ffp-model=strict -c %s 2>&1 \
236+
// RUN: | FileCheck --check-prefixes=CHECK-FASTMATH-FPM-STRICT,WARN-CX-BASIC-TO-FULL %s
198237
// CHECK-FASTMATH-FPM-STRICT: "-cc1"
199238
// CHECK-FASTMATH-FPM-STRICT-NOT: "-menable-no-infs"
200239
// CHECK-FASTMATH-FPM-STRICT-NOT: "-menable-no-nans"
@@ -207,3 +246,4 @@
207246
// CHECK-FASTMATH-FPM-STRICT-NOT: "-fno-rounding-math"
208247
// CHECK-FASTMATH-FPM-STRICT-NOT: "-ffast-math"
209248
// CHECK-FASTMATH-FPM-STRICT-NOT: "-ffinite-math-only"
249+
// CHECK-FASTMATH-FPM-STRICT: "-complex-range=full"

0 commit comments

Comments
 (0)