summaryrefslogtreecommitdiff
path: root/clang
diff options
context:
space:
mode:
authorMichael Klemm <michael.klemm@amd.com>2025-11-22 12:55:32 +0100
committerGitHub <noreply@github.com>2025-11-22 12:55:32 +0100
commit9daf4345ec836d50740805c878bd570dd4093354 (patch)
tree75c7258d83b510d54f0e51907b6b4b4e748e5a96 /clang
parent7305b6eb5458b5cea62b3ab70da95b790cf988f3 (diff)
[Flang] Add -ffast-real-mod back for further control of MOD optimizations (#167118)
It turns out that having `-ffast-math` as the only option to control optimizations for MOD for REAL kinds (PR #160660) is too coarse-grained for some applications. Thus, this PR adds back `-ffast-real-mod` to have more control over the optimization. The `-ffast-math` flag will still enable the optimization, and `-fno-fast-real-mod` allows one to disable it.
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Options/Options.td3
-rw-r--r--clang/lib/Driver/ToolChains/Flang.cpp10
2 files changed, 11 insertions, 2 deletions
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index a2101f061af4..34a6651d2445 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -2788,6 +2788,9 @@ def fno_unsafe_math_optimizations : Flag<["-"], "fno-unsafe-math-optimizations">
Group<f_Group>;
def fassociative_math : Flag<["-"], "fassociative-math">, Visibility<[ClangOption, FlangOption]>, Group<f_Group>;
def fno_associative_math : Flag<["-"], "fno-associative-math">, Visibility<[ClangOption, FlangOption]>, Group<f_Group>;
+def ffast_real_mod : Flag<["-"], "ffast-real-mod">,
+ Group<f_Group>, Visibility<[FlangOption, FC1Option]>,
+ HelpText<"Enable optimization of MOD for REAL types">;
def fno_fast_real_mod : Flag<["-"], "fno-fast-real-mod">,
Group<f_Group>, Visibility<[FlangOption, FC1Option]>,
HelpText<"Disable optimization of MOD for REAL types in presence of -ffast-math">;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 270904de544d..cc4755cd6a9b 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -822,8 +822,14 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
complexRangeKindToStr(Range)));
}
- if (Args.hasArg(options::OPT_fno_fast_real_mod))
- CmdArgs.push_back("-fno-fast-real-mod");
+ if (llvm::opt::Arg *A =
+ Args.getLastArg(clang::options::OPT_ffast_real_mod,
+ clang::options::OPT_fno_fast_real_mod)) {
+ if (A->getOption().matches(clang::options::OPT_ffast_real_mod))
+ CmdArgs.push_back("-ffast-real-mod");
+ else if (A->getOption().matches(clang::options::OPT_fno_fast_real_mod))
+ CmdArgs.push_back("-fno-fast-real-mod");
+ }
if (!HonorINFs && !HonorNaNs && AssociativeMath && ReciprocalMath &&
ApproxFunc && !SignedZeros &&