Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -5444,9 +5444,6 @@ HelpText<"Specify which frame pointers to retain.">, Values<"all,non-leaf,none">, NormalizedValuesScope<"CodeGenOptions::FramePointerKind">, NormalizedValues<["All", "NonLeaf", "None"]>, MarshallingInfoEnum, "None">; -def mreassociate : Flag<["-"], "mreassociate">, - HelpText<"Allow reassociation transformations for floating-point instructions">, - MarshallingInfoFlag>, ImpliedByAnyOf<[funsafe_math_optimizations.KeyPath]>; def mabi_EQ_ieeelongdouble : Flag<["-"], "mabi=ieeelongdouble">, HelpText<"Use IEEE 754 quadruple-precision for long double">, MarshallingInfoFlag>; @@ -6054,6 +6051,9 @@ let Flags = [CC1Option, FC1Option, NoDriverOption] in { +def mreassociate : Flag<["-"], "mreassociate">, + HelpText<"Allow reassociation transformations for floating-point instructions">, + MarshallingInfoFlag>, ImpliedByAnyOf<[funsafe_math_optimizations.KeyPath]>; def menable_no_nans : Flag<["-"], "menable-no-nans">, HelpText<"Allow optimization to assume there are no NaNs.">, MarshallingInfoFlag>, ImpliedByAnyOf<[ffinite_math_only.KeyPath]>; Index: clang/lib/Driver/ToolChains/Flang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Flang.cpp +++ clang/lib/Driver/ToolChains/Flang.cpp @@ -87,6 +87,7 @@ 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 @@ 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 @@ if (!SignedZeros) CmdArgs.push_back("-fno-signed-zeros"); + + if (AssociativeMath && !SignedZeros) + CmdArgs.push_back("-mreassociate"); } void Flang::ConstructJob(Compilation &C, const JobAction &JA, Index: flang/include/flang/Frontend/LangOptions.def =================================================================== --- flang/include/flang/Frontend/LangOptions.def +++ flang/include/flang/Frontend/LangOptions.def @@ -29,6 +29,8 @@ 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 Index: flang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- flang/lib/Frontend/CompilerInvocation.cpp +++ flang/lib/Frontend/CompilerInvocation.cpp @@ -715,6 +715,12 @@ 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; } Index: flang/test/Driver/driver-help.f90 =================================================================== --- flang/test/Driver/driver-help.f90 +++ flang/test/Driver/driver-help.f90 @@ -140,6 +140,7 @@ ! HELP-FC1-NEXT: -mmlir Additional arguments to forward to MLIR's option processing ! HELP-FC1-NEXT: -module-dir Put MODULE files in ! HELP-FC1-NEXT: -module-suffix Use 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 ! HELP-FC1-NEXT: The relocation model to use ! HELP-FC1-NEXT: -nocpp Disable predefined and command line preprocessor macros Index: flang/test/Driver/flang_fp_opts.f90 =================================================================== --- flang/test/Driver/flang_fp_opts.f90 +++ 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 Index: flang/test/Driver/frontend-forwarding.f90 =================================================================== --- flang/test/Driver/frontend-forwarding.f90 +++ 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"