diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1888,7 +1888,7 @@ def fno_associative_math : Flag<["-"], "fno-associative-math">, Group; defm reciprocal_math : BoolFOption<"reciprocal-math", LangOpts<"AllowRecip">, DefaultFalse, - PosFlag, NegFlag>; defm approx_func : BoolFOption<"approx-func", LangOpts<"ApproxFunc">, DefaultFalse, diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -88,6 +88,7 @@ bool ApproxFunc = false; bool SignedZeros = true; bool AssociativeMath = false; + bool ReciprocalMath = false; if (const Arg *A = Args.getLastArg(options::OPT_ffp_contract)) { const StringRef Val = A->getValue(); @@ -143,6 +144,12 @@ case options::OPT_fno_associative_math: AssociativeMath = false; break; + case options::OPT_freciprocal_math: + ReciprocalMath = true; + break; + case options::OPT_fno_reciprocal_math: + ReciprocalMath = false; + break; } // If we handled this option claim it @@ -166,6 +173,9 @@ if (AssociativeMath && !SignedZeros) CmdArgs.push_back("-mreassociate"); + + if (ReciprocalMath) + CmdArgs.push_back("-freciprocal-math"); } void Flang::ConstructJob(Compilation &C, const JobAction &JA, diff --git a/flang/include/flang/Frontend/LangOptions.def b/flang/include/flang/Frontend/LangOptions.def --- a/flang/include/flang/Frontend/LangOptions.def +++ b/flang/include/flang/Frontend/LangOptions.def @@ -31,6 +31,8 @@ LANGOPT(NoSignedZeros, 1, false) /// Allow reassociation transformations for floating-point instructions LANGOPT(AssociativeMath, 1, false) +/// Allow division operations to be reassociated +LANGOPT(ReciprocalMath, 1, false) #undef LANGOPT #undef ENUM_LANGOPT diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -726,6 +726,12 @@ opts.AssociativeMath = true; } + if (const llvm::opt::Arg *a = + args.getLastArg(clang::driver::options::OPT_freciprocal_math)) { + diags.Report(diagUnimplemented) << a->getOption().getName(); + opts.ReciprocalMath = true; + } + return true; } diff --git a/flang/test/Driver/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90 --- a/flang/test/Driver/driver-help-hidden.f90 +++ b/flang/test/Driver/driver-help-hidden.f90 @@ -48,6 +48,7 @@ ! CHECK-NEXT: -fno-signed-zeros Allow optimizations that ignore the sign of floating point zeros ! CHECK-NEXT: -fopenacc Enable OpenACC ! CHECK-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. +! CHECK-NEXT: -freciprocal-math Allow division operations to be reassociated ! CHECK-NEXT: -fsyntax-only Run the preprocessor, parser and semantic analysis stages ! CHECK-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. ! CHECK-NEXT: -help Display available options diff --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90 --- a/flang/test/Driver/driver-help.f90 +++ b/flang/test/Driver/driver-help.f90 @@ -46,6 +46,7 @@ ! HELP-NEXT: -fno-signed-zeros Allow optimizations that ignore the sign of floating point zeros ! HELP-NEXT: -fopenacc Enable OpenACC ! HELP-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. +! HELP-NEXT: -freciprocal-math Allow division operations to be reassociated ! HELP-NEXT: -fsyntax-only Run the preprocessor, parser and semantic analysis stages ! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. ! HELP-NEXT: -help Display available options @@ -128,6 +129,7 @@ ! HELP-FC1-NEXT: -fno-signed-zeros Allow optimizations that ignore the sign of floating point zeros ! HELP-FC1-NEXT: -fopenacc Enable OpenACC ! HELP-FC1-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. +! HELP-FC1-NEXT: -freciprocal-math Allow division operations to be reassociated ! HELP-FC1-NEXT: -fsyntax-only Run the preprocessor, parser and semantic analysis stages ! HELP-FC1-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. ! HELP-FC1-NEXT: -help Display available options diff --git a/flang/test/Driver/flang_fp_opts.f90 b/flang/test/Driver/flang_fp_opts.f90 --- a/flang/test/Driver/flang_fp_opts.f90 +++ b/flang/test/Driver/flang_fp_opts.f90 @@ -7,6 +7,7 @@ ! RUN: -fapprox-func \ ! RUN: -fno-signed-zeros \ ! RUN: -mreassociate \ +! RUN: -freciprocal-math \ ! RUN: %s 2>&1 | FileCheck %s ! CHECK: ffp-contract= is not currently implemented ! CHECK: menable-no-infs is not currently implemented @@ -14,3 +15,4 @@ ! CHECK: fapprox-func is not currently implemented ! CHECK: fno-signed-zeros is not currently implemented ! CHECK: mreassociate is not currently implemented +! CHECK: freciprocal-math is not currently implemented diff --git a/flang/test/Driver/frontend-forwarding.f90 b/flang/test/Driver/frontend-forwarding.f90 --- a/flang/test/Driver/frontend-forwarding.f90 +++ b/flang/test/Driver/frontend-forwarding.f90 @@ -14,6 +14,7 @@ ! RUN: -fapprox-func \ ! RUN: -fno-signed-zeros \ ! RUN: -fassociative-math \ +! RUN: -freciprocal-math \ ! RUN: -mllvm -print-before-all\ ! RUN: -P \ ! RUN: | FileCheck %s @@ -30,5 +31,6 @@ ! CHECK: "-fapprox-func" ! CHECK: "-fno-signed-zeros" ! CHECK: "-mreassociate" +! CHECK: "-freciprocal-math" ! CHECK: "-fconvert=little-endian" ! CHECK: "-mllvm" "-print-before-all"