Author: Tom Eccles Date: 2022-11-04T17:22:35Z New Revision: c4dc3c029416a25103d631e8dc5422f65c076376
URL: https://github.com/llvm/llvm-project/commit/c4dc3c029416a25103d631e8dc5422f65c076376 DIFF: https://github.com/llvm/llvm-project/commit/c4dc3c029416a25103d631e8dc5422f65c076376.diff LOG: [flang] Add -f[no-]associative-math and -mreassociate Only add the option processing and store the result. No attributes are added to FIR yet. Clang only forwards -mreassociate if (AssociativeMath && !SignedZeros && !TrappingMath) Flang doesn't have -f[no-]trapping-math, so this part of the condition has been omitted. !TrappingMath is the default. Differential Revision: https://reviews.llvm.org/D137329 Added: Modified: clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/Flang.cpp flang/include/flang/Frontend/LangOptions.def flang/lib/Frontend/CompilerInvocation.cpp flang/test/Driver/driver-help.f90 flang/test/Driver/flang_fp_opts.f90 flang/test/Driver/frontend-forwarding.f90 Removed: ################################################################################ diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 99500918d8bf7..77c84396fa995 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5444,9 +5444,6 @@ def mframe_pointer_EQ : Joined<["-"], "mframe-pointer=">, HelpText<"Specify which frame pointers to retain.">, Values<"all,non-leaf,none">, NormalizedValuesScope<"CodeGenOptions::FramePointerKind">, NormalizedValues<["All", "NonLeaf", "None"]>, MarshallingInfoEnum<CodeGenOpts<"FramePointer">, "None">; -def mreassociate : Flag<["-"], "mreassociate">, - HelpText<"Allow reassociation transformations for floating-point instructions">, - MarshallingInfoFlag<LangOpts<"AllowFPReassoc">>, ImpliedByAnyOf<[funsafe_math_optimizations.KeyPath]>; def mabi_EQ_ieeelongdouble : Flag<["-"], "mabi=ieeelongdouble">, HelpText<"Use IEEE 754 quadruple-precision for long double">, MarshallingInfoFlag<LangOpts<"PPCIEEELongDouble">>; @@ -6054,6 +6051,9 @@ def split_dwarf_output : Separate<["-"], "split-dwarf-output">, let Flags = [CC1Option, FC1Option, NoDriverOption] in { +def mreassociate : Flag<["-"], "mreassociate">, + HelpText<"Allow reassociation transformations for floating-point instructions">, + MarshallingInfoFlag<LangOpts<"AllowFPReassoc">>, ImpliedByAnyOf<[funsafe_math_optimizations.KeyPath]>; def menable_no_nans : Flag<["-"], "menable-no-nans">, HelpText<"Allow optimization to assume there are no NaNs.">, MarshallingInfoFlag<LangOpts<"NoHonorNaNs">>, ImpliedByAnyOf<[ffinite_math_only.KeyPath]>; diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index a5b47123b9bc4..f51972773a553 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -87,6 +87,7 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args, bool HonorNaNs = true; bool ApproxFunc = false; bool SignedZeros = true; + bool AssociativeMath = false; if (const Arg *A = Args.getLastArg(options::OPT_ffp_contract)) { const StringRef Val = A->getValue(); @@ -136,6 +137,12 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args, case options::OPT_fno_signed_zeros: SignedZeros = false; break; + case options::OPT_fassociative_math: + AssociativeMath = true; + break; + case options::OPT_fno_associative_math: + AssociativeMath = false; + break; } // If we handled this option claim it @@ -156,6 +163,9 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args, if (!SignedZeros) CmdArgs.push_back("-fno-signed-zeros"); + + if (AssociativeMath && !SignedZeros) + CmdArgs.push_back("-mreassociate"); } void Flang::ConstructJob(Compilation &C, const JobAction &JA, diff --git a/flang/include/flang/Frontend/LangOptions.def b/flang/include/flang/Frontend/LangOptions.def index e357182f50757..059e3d18dfc8a 100644 --- a/flang/include/flang/Frontend/LangOptions.def +++ b/flang/include/flang/Frontend/LangOptions.def @@ -29,6 +29,8 @@ LANGOPT(NoHonorNaNs, 1, false) LANGOPT(ApproxFunc, 1, false) /// Allow optimizations that ignore the sign of floating point zeros LANGOPT(NoSignedZeros, 1, false) +/// Allow reassociation transformations for floating-point instructions +LANGOPT(AssociativeMath, 1, false) #undef LANGOPT #undef ENUM_LANGOPT diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index eeadb21c19233..8c0bdcd185b6c 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -720,6 +720,12 @@ static bool parseFloatingPointArgs(CompilerInvocation &invoc, opts.NoSignedZeros = true; } + if (const llvm::opt::Arg *a = + args.getLastArg(clang::driver::options::OPT_mreassociate)) { + diags.Report(diagUnimplemented) << a->getOption().getName(); + opts.AssociativeMath = true; + } + return true; } diff --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90 index 1c48ec572443e..32b6f7615deca 100644 --- a/flang/test/Driver/driver-help.f90 +++ b/flang/test/Driver/driver-help.f90 @@ -140,6 +140,7 @@ ! HELP-FC1-NEXT: -mmlir <value> Additional arguments to forward to MLIR's option processing ! HELP-FC1-NEXT: -module-dir <dir> Put MODULE files in <dir> ! HELP-FC1-NEXT: -module-suffix <suffix> Use <suffix> as the suffix for module files (the default value is `.mod`) +! HELP-FC1-NEXT: -mreassociate Allow reassociation transformations for floating-point instructions ! HELP-FC1-NEXT: -mrelocation-model <value> ! HELP-FC1-NEXT: The relocation model to use ! HELP-FC1-NEXT: -nocpp Disable predefined and command line preprocessor macros diff --git a/flang/test/Driver/flang_fp_opts.f90 b/flang/test/Driver/flang_fp_opts.f90 index a305cddef4d2f..bbe886bcec878 100644 --- a/flang/test/Driver/flang_fp_opts.f90 +++ b/flang/test/Driver/flang_fp_opts.f90 @@ -6,9 +6,11 @@ ! RUN: -menable-no-nans \ ! RUN: -fapprox-func \ ! RUN: -fno-signed-zeros \ +! RUN: -mreassociate \ ! RUN: %s 2>&1 | FileCheck %s ! CHECK: ffp-contract= is not currently implemented ! CHECK: menable-no-infs is not currently implemented ! CHECK: menable-no-nans is not currently implemented ! CHECK: fapprox-func is not currently implemented ! CHECK: fno-signed-zeros is not currently implemented +! CHECK: mreassociate is not currently implemented diff --git a/flang/test/Driver/frontend-forwarding.f90 b/flang/test/Driver/frontend-forwarding.f90 index a00c45a9c154f..de3ed6ddbfca8 100644 --- a/flang/test/Driver/frontend-forwarding.f90 +++ b/flang/test/Driver/frontend-forwarding.f90 @@ -13,6 +13,7 @@ ! RUN: -fno-honor-nans \ ! RUN: -fapprox-func \ ! RUN: -fno-signed-zeros \ +! RUN: -fassociative-math \ ! RUN: -mllvm -print-before-all\ ! RUN: -P \ ! RUN: | FileCheck %s @@ -28,5 +29,6 @@ ! CHECK: "-menable-no-nans" ! CHECK: "-fapprox-func" ! CHECK: "-fno-signed-zeros" +! CHECK: "-mreassociate" ! CHECK: "-fconvert=little-endian" ! CHECK: "-mllvm" "-print-before-all" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits