[clang] [clang] Enable FPContract with optnone (PR #91061)

via cfe-commits cfe-commits at lists.llvm.org
Sat May 4 14:44:32 PDT 2024


================
@@ -968,10 +968,7 @@ class FPOptionsOverride {
       setAllowFPContractAcrossStatement();
   }
 
-  void setDisallowOptimizations() {
-    setFPPreciseEnabled(true);
-    setDisallowFPContract();
-  }
+  void setDisallowOptimizations() { setFPPreciseEnabled(true); }
----------------
wjristow wrote:

Actually, instead of just removing the call to `setDisallowFPContract()`, we should instead explicitly set the FP Contraction state to "on" (which is the default at `-O0`).  That is, we should call `setAllowFPContractWithinStatement()`.

In particular, if the user is compiling with `-ffast-math`, then the FP Contraction state will be `-ffp-contract=fast` (allowing FMA across multiple statements).  And if they applied `optnone`, then by removing the call to `setDisallowFPContract()`, we would mistakenly leave that inter-statement FMA enabled.  By calling `setAllowFPContractWithinStatement()` we are explicitly setting it the equivalent of the command-line option `-ffp-contract=on`, which is the desired state of `-O0` (and `optnone`).

https://github.com/llvm/llvm-project/pull/91061


More information about the cfe-commits mailing list