Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -1919,7 +1919,7 @@ // This option was originally misspelt "infinites" [sic]. def : Flag<["-"], "fhonor-infinites">, Alias; def : Flag<["-"], "fno-honor-infinites">, Alias; -def frounding_math : Flag<["-"], "frounding-math">, Group, Flags<[CC1Option]>, +def frounding_math : Flag<["-"], "frounding-math">, Group, Flags<[CC1Option, FC1Option]>, MarshallingInfoFlag>, Normalizer<"makeFlagToValueNormalizer(llvm::RoundingMode::Dynamic)">; def fno_rounding_math : Flag<["-"], "fno-rounding-math">, Group, Flags<[CC1Option]>; Index: clang/lib/Driver/ToolChains/Flang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Flang.cpp +++ clang/lib/Driver/ToolChains/Flang.cpp @@ -89,6 +89,7 @@ bool SignedZeros = true; bool AssociativeMath = false; bool ReciprocalMath = false; + bool RoundingFPMath = false; if (const Arg *A = Args.getLastArg(options::OPT_ffp_contract)) { const StringRef Val = A->getValue(); @@ -150,6 +151,12 @@ case options::OPT_fno_reciprocal_math: ReciprocalMath = false; break; + case options::OPT_frounding_math: + RoundingFPMath = true; + break; + case options::OPT_fno_rounding_math: + RoundingFPMath = false; + break; } // If we handled this option claim it @@ -176,6 +183,9 @@ if (ReciprocalMath) CmdArgs.push_back("-freciprocal-math"); + + if (RoundingFPMath) + CmdArgs.push_back("-frounding-math"); } void Flang::ConstructJob(Compilation &C, const JobAction &JA, Index: flang/include/flang/Common/MathOptionsBase.def =================================================================== --- flang/include/flang/Common/MathOptionsBase.def +++ flang/include/flang/Common/MathOptionsBase.def @@ -38,4 +38,7 @@ /// Allow division operations to be reassociated ENUM_MATHOPT(ReciprocalMath, unsigned, 1, 0) +/// Do not assume default floating-point rounding behavior +ENUM_MATHOPT(RoundingMath, unsigned, 1, 0) + #undef ENUM_MATHOPT Index: flang/include/flang/Frontend/LangOptions.def =================================================================== --- flang/include/flang/Frontend/LangOptions.def +++ flang/include/flang/Frontend/LangOptions.def @@ -34,6 +34,8 @@ LANGOPT(AssociativeMath, 1, false) /// Allow division operations to be reassociated LANGOPT(ReciprocalMath, 1, false) +/// Do not assume default floating-point rounding behavior +LANGOPT(RoundingMath, 1, false) #undef LANGOPT #undef ENUM_LANGOPT Index: flang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- flang/lib/Frontend/CompilerInvocation.cpp +++ flang/lib/Frontend/CompilerInvocation.cpp @@ -735,6 +735,12 @@ opts.ReciprocalMath = true; } + if (const llvm::opt::Arg *a = + args.getLastArg(clang::driver::options::OPT_frounding_math)) { + diags.Report(diagUnimplemented) << a->getOption().getName(); + opts.RoundingMath = true; + } + return true; } @@ -965,5 +971,6 @@ .setApproxFunc(langOptions.ApproxFunc) .setNoSignedZeros(langOptions.NoSignedZeros) .setAssociativeMath(langOptions.AssociativeMath) - .setReciprocalMath(langOptions.ReciprocalMath); + .setReciprocalMath(langOptions.ReciprocalMath) + .setRoundingMath(langOptions.RoundingMath); } Index: flang/lib/Optimizer/Builder/FIRBuilder.cpp =================================================================== --- flang/lib/Optimizer/Builder/FIRBuilder.cpp +++ flang/lib/Optimizer/Builder/FIRBuilder.cpp @@ -619,6 +619,7 @@ if (options.getReciprocalMath()) { arithFMF = arithFMF | mlir::arith::FastMathFlags::arcp; } + // TODO: getRoundingMath() setFastMathFlags(arithFMF); } Index: flang/test/Driver/flang_fp_opts.f90 =================================================================== --- flang/test/Driver/flang_fp_opts.f90 +++ flang/test/Driver/flang_fp_opts.f90 @@ -8,6 +8,7 @@ ! RUN: -fno-signed-zeros \ ! RUN: -mreassociate \ ! RUN: -freciprocal-math \ +! RUN: -frounding-math \ ! RUN: %s 2>&1 | FileCheck %s ! CHECK: ffp-contract= is not currently implemented ! CHECK: menable-no-infs is not currently implemented @@ -16,3 +17,4 @@ ! CHECK: fno-signed-zeros is not currently implemented ! CHECK: mreassociate is not currently implemented ! CHECK: freciprocal-math is not currently implemented +! CHECK: frounding-math is not currently implemented Index: flang/test/Driver/frontend-forwarding.f90 =================================================================== --- flang/test/Driver/frontend-forwarding.f90 +++ flang/test/Driver/frontend-forwarding.f90 @@ -15,6 +15,7 @@ ! RUN: -fno-signed-zeros \ ! RUN: -fassociative-math \ ! RUN: -freciprocal-math \ +! RUN: -frounding-math \ ! RUN: -fpass-plugin=Bye%pluginext \ ! RUN: -mllvm -print-before-all\ ! RUN: -P \ @@ -33,6 +34,7 @@ ! CHECK: "-fno-signed-zeros" ! CHECK: "-mreassociate" ! CHECK: "-freciprocal-math" +! CHECK: "-frounding-math" ! CHECK: "-fconvert=little-endian" ! CHECK: "-fpass-plugin=Bye ! CHECK: "-mllvm" "-print-before-all"