[clang] 0140ba0 - [clang] Enable FPContract with optnone (#91061)

via cfe-commits cfe-commits at lists.llvm.org
Mon May 6 00:30:58 PDT 2024


Author: Serge Pavlov
Date: 2024-05-06T14:30:54+07:00
New Revision: 0140ba031c9b6a4028b36adb292fb37eb62f3dc0

URL: https://github.com/llvm/llvm-project/commit/0140ba031c9b6a4028b36adb292fb37eb62f3dc0
DIFF: https://github.com/llvm/llvm-project/commit/0140ba031c9b6a4028b36adb292fb37eb62f3dc0.diff

LOG: [clang] Enable FPContract with optnone (#91061)

Previously treatment of the attribute `optnone` was modified in
https://github.com/llvm/llvm-project/pull/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
https://github.com/llvm/llvm-project/pull/85605#issuecomment-2089350379
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.

Added: 
    

Modified: 
    clang/include/clang/Basic/LangOptions.h
    clang/test/AST/ast-dump-fpfeatures.cpp
    clang/test/AST/ast-dump-fpfeatures.m
    clang/test/AST/ast-dump-late-parsing.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h
index e2a2aa71b880b3..75e88afbd97050 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -968,10 +968,7 @@ class FPOptionsOverride {
       setAllowFPContractAcrossStatement();
   }
 
-  void setDisallowOptimizations() {
-    setFPPreciseEnabled(true);
-    setDisallowFPContract();
-  }
+  void setDisallowOptimizations() { setFPPreciseEnabled(true); }
 
   storage_type getAsOpaqueInt() const {
     return (static_cast<storage_type>(Options.getAsOpaqueInt())

diff  --git a/clang/test/AST/ast-dump-fpfeatures.cpp b/clang/test/AST/ast-dump-fpfeatures.cpp
index 2c66a73812f5b3..cd00650db55cc9 100644
--- a/clang/test/AST/ast-dump-fpfeatures.cpp
+++ b/clang/test/AST/ast-dump-fpfeatures.cpp
@@ -198,7 +198,7 @@ float func_19(float x, float y) {
 // CHECK-LABEL: FunctionDecl {{.*}} func_19 'float (float, float)'
 // CHECK:         CompoundStmt {{.*}} MathErrno=1
 // CHECK:           ReturnStmt
-// CHECK:             BinaryOperator {{.*}} 'float' '+' ConstRoundingMode=downward MathErrno=1
+// CHECK:             BinaryOperator {{.*}} 'float' '+' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
 
 __attribute__((optnone))
 float func_20(float x, float y) try {
@@ -210,7 +210,7 @@ float func_20(float x, float y) try {
 // CHECK-LABEL: FunctionDecl {{.*}} func_20 'float (float, float)'
 // CHECK:         CompoundStmt {{.*}} ConstRoundingMode=downward MathErrno=1
 // CHECK:           ReturnStmt
-// CHECK:             BinaryOperator {{.*}} 'float' '+' ConstRoundingMode=downward MathErrno=1
+// CHECK:             BinaryOperator {{.*}} 'float' '+' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
 
 struct C21 {
   C21(float x, float y);
@@ -221,15 +221,15 @@ struct C21 {
 };
 
 // CHECK-LABEL: CXXMethodDecl {{.*}} a_method 'float (float, float)'
-// CHECK:         CompoundStmt {{.*}} ConstRoundingMode=downward MathErrno=1
+// CHECK:         CompoundStmt {{.*}} FPContractMode=1 ConstRoundingMode=downward MathErrno=1
 // CHECK:           ReturnStmt
-// CHECK:             BinaryOperator {{.*}} 'float' '*' ConstRoundingMode=downward MathErrno=1
+// CHECK:             BinaryOperator {{.*}} 'float' '*' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
 
 __attribute__((optnone)) C21::C21(float x, float y) : member(x + y) {}
 
 // CHECK-LABEL: CXXConstructorDecl {{.*}} C21 'void (float, float)'
 // CHECK:         CXXCtorInitializer {{.*}} 'member' 'float'
-// CHECK:           BinaryOperator {{.*}} 'float' '+' ConstRoundingMode=downward MathErrno=1
+// CHECK:           BinaryOperator {{.*}} 'float' '+' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
 
 template <typename T>
 __attribute__((optnone)) T func_22(T x, T y) {
@@ -238,13 +238,13 @@ __attribute__((optnone)) T func_22(T x, T y) {
 
 // CHECK-LABEL: FunctionTemplateDecl {{.*}} func_22
 // CHECK:         FunctionDecl {{.*}} func_22 'T (T, T)'
-// CHECK:           CompoundStmt {{.*}} ConstRoundingMode=downward MathErrno=1
+// CHECK:           CompoundStmt {{.*}} FPContractMode=1 ConstRoundingMode=downward MathErrno=1
 // CHECK:             ReturnStmt
-// CHECK:               BinaryOperator {{.*}} '+' ConstRoundingMode=downward MathErrno=1
+// CHECK:               BinaryOperator {{.*}} '+' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
 // CHECK:         FunctionDecl {{.*}} func_22 'float (float, float)'
-// CHECK:           CompoundStmt {{.*}} ConstRoundingMode=downward MathErrno=1
+// CHECK:           CompoundStmt {{.*}} FPContractMode=1 ConstRoundingMode=downward MathErrno=1
 // CHECK:             ReturnStmt
-// CHECK:               BinaryOperator {{.*}} 'float' '+' ConstRoundingMode=downward MathErrno=1
+// CHECK:               BinaryOperator {{.*}} 'float' '+' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
 
 float func_23(float x, float y) {
   return func_22(x, y);

diff  --git a/clang/test/AST/ast-dump-fpfeatures.m b/clang/test/AST/ast-dump-fpfeatures.m
index 66d639918ae1f8..e390d5b676864e 100644
--- a/clang/test/AST/ast-dump-fpfeatures.m
+++ b/clang/test/AST/ast-dump-fpfeatures.m
@@ -24,6 +24,6 @@ - (float) sum: (float)x with: (float)y __attribute((optnone)) {
 
 // CHECK-LABEL: ObjCImplementationDecl {{.*}} Adder
 // CHECK:         ObjCMethodDecl {{.*}} - sum:with: 'float'
-// CHECK:           CompoundStmt {{.*}} MathErrno=1
+// CHECK:           CompoundStmt {{.*}} FPContractMode=1 MathErrno=1
 // CHECK-NEXT:        ReturnStmt
-// CHECK-NEXT:          BinaryOperator {{.*}} 'float' '+' MathErrno=1
+// CHECK-NEXT:          BinaryOperator {{.*}} 'float' '+' FPContractMode=1 MathErrno=1

diff  --git a/clang/test/AST/ast-dump-late-parsing.cpp b/clang/test/AST/ast-dump-late-parsing.cpp
index 45efb2b88e2a3d..5115caaa59f5e1 100644
--- a/clang/test/AST/ast-dump-late-parsing.cpp
+++ b/clang/test/AST/ast-dump-late-parsing.cpp
@@ -11,13 +11,13 @@ __attribute__((optnone)) T func_22(T x, T y) {
 
 // CHECK-LABEL: FunctionTemplateDecl {{.*}} func_22
 // CHECK:         FunctionDecl {{.*}} func_22 'T (T, T)'
-// CHECK:           CompoundStmt {{.*}} ConstRoundingMode=downward MathErrno=1
+// CHECK:           CompoundStmt {{.*}} FPContractMode=1 ConstRoundingMode=downward MathErrno=1
 // CHECK:             ReturnStmt
-// CHECK:               BinaryOperator {{.*}} '+' ConstRoundingMode=downward MathErrno=1
+// CHECK:               BinaryOperator {{.*}} '+' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
 // CHECK:         FunctionDecl {{.*}} func_22 'float (float, float)'
-// CHECK:           CompoundStmt {{.*}} ConstRoundingMode=downward MathErrno=1
+// CHECK:           CompoundStmt {{.*}} FPContractMode=1 ConstRoundingMode=downward MathErrno=1
 // CHECK:             ReturnStmt
-// CHECK:               BinaryOperator {{.*}} 'float' '+' ConstRoundingMode=downward MathErrno=1
+// CHECK:               BinaryOperator {{.*}} 'float' '+' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
 
 float func_23(float x, float y) {
   return func_22(x, y);


        


More information about the cfe-commits mailing list