Skip to content

Commit 0140ba0

Browse files
authored
[clang] Enable FPContract with optnone (#91061)
Previously treatment of the attribute `optnone` was modified in #85605 ([clang] Set correct FPOptions if attribute 'optnone' presents). As a side effect FPContract was disabled for optnone. It created unneeded divergence with the behavior of -O0, which enables this optimization. In the discussion #85605 (comment) it was pointed out that FP contraction should be enabled even if all optimizations are turned off, otherwise results of calculations would be different. This change enables FPContract at optnone.
1 parent d654278 commit 0140ba0

File tree

4 files changed

+16
-19
lines changed

4 files changed

+16
-19
lines changed

clang/include/clang/Basic/LangOptions.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -968,10 +968,7 @@ class FPOptionsOverride {
968968
setAllowFPContractAcrossStatement();
969969
}
970970

971-
void setDisallowOptimizations() {
972-
setFPPreciseEnabled(true);
973-
setDisallowFPContract();
974-
}
971+
void setDisallowOptimizations() { setFPPreciseEnabled(true); }
975972

976973
storage_type getAsOpaqueInt() const {
977974
return (static_cast<storage_type>(Options.getAsOpaqueInt())

clang/test/AST/ast-dump-fpfeatures.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ float func_19(float x, float y) {
198198
// CHECK-LABEL: FunctionDecl {{.*}} func_19 'float (float, float)'
199199
// CHECK: CompoundStmt {{.*}} MathErrno=1
200200
// CHECK: ReturnStmt
201-
// CHECK: BinaryOperator {{.*}} 'float' '+' ConstRoundingMode=downward MathErrno=1
201+
// CHECK: BinaryOperator {{.*}} 'float' '+' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
202202

203203
__attribute__((optnone))
204204
float func_20(float x, float y) try {
@@ -210,7 +210,7 @@ float func_20(float x, float y) try {
210210
// CHECK-LABEL: FunctionDecl {{.*}} func_20 'float (float, float)'
211211
// CHECK: CompoundStmt {{.*}} ConstRoundingMode=downward MathErrno=1
212212
// CHECK: ReturnStmt
213-
// CHECK: BinaryOperator {{.*}} 'float' '+' ConstRoundingMode=downward MathErrno=1
213+
// CHECK: BinaryOperator {{.*}} 'float' '+' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
214214

215215
struct C21 {
216216
C21(float x, float y);
@@ -221,15 +221,15 @@ struct C21 {
221221
};
222222

223223
// CHECK-LABEL: CXXMethodDecl {{.*}} a_method 'float (float, float)'
224-
// CHECK: CompoundStmt {{.*}} ConstRoundingMode=downward MathErrno=1
224+
// CHECK: CompoundStmt {{.*}} FPContractMode=1 ConstRoundingMode=downward MathErrno=1
225225
// CHECK: ReturnStmt
226-
// CHECK: BinaryOperator {{.*}} 'float' '*' ConstRoundingMode=downward MathErrno=1
226+
// CHECK: BinaryOperator {{.*}} 'float' '*' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
227227

228228
__attribute__((optnone)) C21::C21(float x, float y) : member(x + y) {}
229229

230230
// CHECK-LABEL: CXXConstructorDecl {{.*}} C21 'void (float, float)'
231231
// CHECK: CXXCtorInitializer {{.*}} 'member' 'float'
232-
// CHECK: BinaryOperator {{.*}} 'float' '+' ConstRoundingMode=downward MathErrno=1
232+
// CHECK: BinaryOperator {{.*}} 'float' '+' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
233233

234234
template <typename T>
235235
__attribute__((optnone)) T func_22(T x, T y) {
@@ -238,13 +238,13 @@ __attribute__((optnone)) T func_22(T x, T y) {
238238

239239
// CHECK-LABEL: FunctionTemplateDecl {{.*}} func_22
240240
// CHECK: FunctionDecl {{.*}} func_22 'T (T, T)'
241-
// CHECK: CompoundStmt {{.*}} ConstRoundingMode=downward MathErrno=1
241+
// CHECK: CompoundStmt {{.*}} FPContractMode=1 ConstRoundingMode=downward MathErrno=1
242242
// CHECK: ReturnStmt
243-
// CHECK: BinaryOperator {{.*}} '+' ConstRoundingMode=downward MathErrno=1
243+
// CHECK: BinaryOperator {{.*}} '+' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
244244
// CHECK: FunctionDecl {{.*}} func_22 'float (float, float)'
245-
// CHECK: CompoundStmt {{.*}} ConstRoundingMode=downward MathErrno=1
245+
// CHECK: CompoundStmt {{.*}} FPContractMode=1 ConstRoundingMode=downward MathErrno=1
246246
// CHECK: ReturnStmt
247-
// CHECK: BinaryOperator {{.*}} 'float' '+' ConstRoundingMode=downward MathErrno=1
247+
// CHECK: BinaryOperator {{.*}} 'float' '+' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
248248

249249
float func_23(float x, float y) {
250250
return func_22(x, y);

clang/test/AST/ast-dump-fpfeatures.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ - (float) sum: (float)x with: (float)y __attribute((optnone)) {
2424

2525
// CHECK-LABEL: ObjCImplementationDecl {{.*}} Adder
2626
// CHECK: ObjCMethodDecl {{.*}} - sum:with: 'float'
27-
// CHECK: CompoundStmt {{.*}} MathErrno=1
27+
// CHECK: CompoundStmt {{.*}} FPContractMode=1 MathErrno=1
2828
// CHECK-NEXT: ReturnStmt
29-
// CHECK-NEXT: BinaryOperator {{.*}} 'float' '+' MathErrno=1
29+
// CHECK-NEXT: BinaryOperator {{.*}} 'float' '+' FPContractMode=1 MathErrno=1

clang/test/AST/ast-dump-late-parsing.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ __attribute__((optnone)) T func_22(T x, T y) {
1111

1212
// CHECK-LABEL: FunctionTemplateDecl {{.*}} func_22
1313
// CHECK: FunctionDecl {{.*}} func_22 'T (T, T)'
14-
// CHECK: CompoundStmt {{.*}} ConstRoundingMode=downward MathErrno=1
14+
// CHECK: CompoundStmt {{.*}} FPContractMode=1 ConstRoundingMode=downward MathErrno=1
1515
// CHECK: ReturnStmt
16-
// CHECK: BinaryOperator {{.*}} '+' ConstRoundingMode=downward MathErrno=1
16+
// CHECK: BinaryOperator {{.*}} '+' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
1717
// CHECK: FunctionDecl {{.*}} func_22 'float (float, float)'
18-
// CHECK: CompoundStmt {{.*}} ConstRoundingMode=downward MathErrno=1
18+
// CHECK: CompoundStmt {{.*}} FPContractMode=1 ConstRoundingMode=downward MathErrno=1
1919
// CHECK: ReturnStmt
20-
// CHECK: BinaryOperator {{.*}} 'float' '+' ConstRoundingMode=downward MathErrno=1
20+
// CHECK: BinaryOperator {{.*}} 'float' '+' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
2121

2222
float func_23(float x, float y) {
2323
return func_22(x, y);

0 commit comments

Comments
 (0)