diff options
author | Zahira Ammarguellat <zahira.ammarguellat@intel.com> | 2022-11-07 13:54:42 -0500 |
---|---|---|
committer | Zahira Ammarguellat <zahira.ammarguellat@intel.com> | 2022-11-11 10:24:12 -0500 |
commit | 91628f0616ca5203945afb56b3d8a27522b99808 (patch) | |
tree | bb0ab9a4ac858c518db540009d50020eec1f09dc /clang/lib | |
parent | 2116d69f100c243069be1e76ac7fdac65ea5328a (diff) | |
download | llvm-91628f0616ca5203945afb56b3d8a27522b99808.zip llvm-91628f0616ca5203945afb56b3d8a27522b99808.tar.gz llvm-91628f0616ca5203945afb56b3d8a27522b99808.tar.bz2 |
The handling of 'funsafe-math-optimizations' doesn't update the 'MathErrno'
flag. But the driver checks for 'fno-math-errno' before passing
'funsafe-math-optimizations' to the FE. In GCC, the option
'funsafe-math-optimizations' doesn't affect the 'fmath-errno' flag.
This patch aligns clang with GCC.
'-ffast-math' sets the FPContract to 'fast'. But 'funsafe-math-optimizations'
the driver doesn't consider the FPContract when handling the option.
Unfortunately there are places in the BE that interpret unsafe math
mode as allowing FMA. This patch makes -ffast-math' and
'funsafe-math-optimizations' behave similarly in regard to the setting of the
FPContract.
Differential Revision: https://reviews.llvm.org/D137578
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Driver/ToolChains/Clang.cpp | 19 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 2 |
2 files changed, 15 insertions, 6 deletions
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 0633618..217a277b 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -2787,7 +2787,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, // If one wasn't given by the user, don't pass it here. StringRef FPContract; StringRef LastSeenFfpContractOption; - bool SeenFfastMathOption = false; + bool SeenUnsafeMathModeOption = false; if (!JA.isDeviceOffloading(Action::OFK_Cuda) && !JA.isOffloading(Action::OFK_HIP)) FPContract = "on"; @@ -3003,6 +3003,8 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, ApproxFunc = true; TrappingMath = false; FPExceptionBehavior = ""; + FPContract = "fast"; + SeenUnsafeMathModeOption = true; break; case options::OPT_fno_unsafe_math_optimizations: AssociativeMath = false; @@ -3015,6 +3017,13 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, // The target may have opted to flush by default, so force IEEE. DenormalFPMath = llvm::DenormalMode::getIEEE(); DenormalFP32Math = llvm::DenormalMode::getIEEE(); + if (!JA.isDeviceOffloading(Action::OFK_Cuda) && + !JA.isOffloading(Action::OFK_HIP)) { + if (LastSeenFfpContractOption != "") { + FPContract = LastSeenFfpContractOption; + } else if (SeenUnsafeMathModeOption) + FPContract = "on"; + } break; case options::OPT_Ofast: @@ -3034,7 +3043,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, RoundingFPMath = false; // If fast-math is set then set the fp-contract mode to fast. FPContract = "fast"; - SeenFfastMathOption = true; + SeenUnsafeMathModeOption = true; break; case options::OPT_fno_fast_math: HonorINFs = true; @@ -3054,7 +3063,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, !JA.isOffloading(Action::OFK_HIP)) { if (LastSeenFfpContractOption != "") { FPContract = LastSeenFfpContractOption; - } else if (SeenFfastMathOption) + } else if (SeenUnsafeMathModeOption) FPContract = "on"; } break; @@ -3095,8 +3104,8 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, if (MathErrno) CmdArgs.push_back("-fmath-errno"); - if (!MathErrno && AssociativeMath && ReciprocalMath && !SignedZeros && - ApproxFunc && !TrappingMath) + if (AssociativeMath && ReciprocalMath && !SignedZeros && ApproxFunc && + !TrappingMath) CmdArgs.push_back("-funsafe-math-optimizations"); if (!SignedZeros) diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 088e83b..40d556f 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -3799,7 +3799,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, else Opts.LongDoubleSize = 0; } - if (Opts.FastRelaxedMath) + if (Opts.FastRelaxedMath || Opts.CLUnsafeMath) Opts.setDefaultFPContractMode(LangOptions::FPM_Fast); llvm::sort(Opts.ModuleFeatures); |