aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
authorZahira Ammarguellat <zahira.ammarguellat@intel.com>2022-04-03 04:28:15 -0700
committerZahira Ammarguellat <zahira.ammarguellat@intel.com>2022-04-05 04:58:19 -0700
commit4d165ad7d9b3395a59c287ef60542b4de3a4d95a (patch)
treee227d96abddf8044e220337afefc6b200665da26 /clang/lib/Frontend/CompilerInvocation.cpp
parentafca54f0cfc3164e1ebbc7ddf27c8e95f0cd12b6 (diff)
downloadllvm-4d165ad7d9b3395a59c287ef60542b4de3a4d95a.zip
llvm-4d165ad7d9b3395a59c287ef60542b4de3a4d95a.tar.gz
llvm-4d165ad7d9b3395a59c287ef60542b4de3a4d95a.tar.bz2
In fast-math mode, when unsafe math optimizations are enabled, the
compiler is allowed to use optimizations that allow reassociation and transformations that don’t guaranty accuracy. For example (x+y)+z is transformed into x+(y+z) . Although mathematically equivalent, these two expressions may not lead to the same final result due to errors of summation. Or x/x is transformed into 1.0 but x could be 0.0, INF or NaN. And so this transformation also may not lead to the same final result. Setting the eval method 'ffp-eval-method' or via '#pragma clang fp eval_method' in this mode, doesn’t have any effect. This patch adds code to warn the user of this. Differential Revision: https://reviews.llvm.org/D122155
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index f8fd3a29..91adacd 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -503,6 +503,22 @@ static bool FixupInvocation(CompilerInvocation &Invocation,
Diags.Report(diag::warn_ignored_hip_only_option)
<< Args.getLastArg(OPT_gpu_max_threads_per_block_EQ)->getAsString(Args);
+ // When these options are used, the compiler is allowed to apply
+ // optimizations that may affect the final result. For example
+ // (x+y)+z is transformed to x+(y+z) but may not give the same
+ // final result; it's not value safe.
+ // Another example can be to simplify x/x to 1.0 but x could be 0.0, INF
+ // or NaN. Final result may then differ. An error is issued when the eval
+ // method is set with one of these options.
+ if (Args.hasArg(OPT_ffp_eval_method_EQ)) {
+ if (LangOpts.ApproxFunc)
+ Diags.Report(diag::err_incompatible_fp_eval_method_options) << 0;
+ if (LangOpts.AllowFPReassoc)
+ Diags.Report(diag::err_incompatible_fp_eval_method_options) << 1;
+ if (LangOpts.AllowRecip)
+ Diags.Report(diag::err_incompatible_fp_eval_method_options) << 2;
+ }
+
// -cl-strict-aliasing needs to emit diagnostic in the case where CL > 1.0.
// This option should be deprecated for CL > 1.0 because
// this option was added for compatibility with OpenCL 1.0.