Skip to content

Commit d0d4b63

Browse files
committed
[flang] add -f[no-]reciprocal-math
Only add the option processing and store the result. No attributes are added to FIR yet. Differential Revision: https://reviews.llvm.org/D137330
1 parent c4dc3c0 commit d0d4b63

File tree

8 files changed

+26
-1
lines changed

8 files changed

+26
-1
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1888,7 +1888,7 @@ def fassociative_math : Flag<["-"], "fassociative-math">, Group<f_Group>;
18881888
def fno_associative_math : Flag<["-"], "fno-associative-math">, Group<f_Group>;
18891889
defm reciprocal_math : BoolFOption<"reciprocal-math",
18901890
LangOpts<"AllowRecip">, DefaultFalse,
1891-
PosFlag<SetTrue, [CC1Option], "Allow division operations to be reassociated",
1891+
PosFlag<SetTrue, [CC1Option, FC1Option, FlangOption], "Allow division operations to be reassociated",
18921892
[funsafe_math_optimizations.KeyPath]>,
18931893
NegFlag<SetFalse>>;
18941894
defm approx_func : BoolFOption<"approx-func", LangOpts<"ApproxFunc">, DefaultFalse,

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
8888
bool ApproxFunc = false;
8989
bool SignedZeros = true;
9090
bool AssociativeMath = false;
91+
bool ReciprocalMath = false;
9192

9293
if (const Arg *A = Args.getLastArg(options::OPT_ffp_contract)) {
9394
const StringRef Val = A->getValue();
@@ -143,6 +144,12 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
143144
case options::OPT_fno_associative_math:
144145
AssociativeMath = false;
145146
break;
147+
case options::OPT_freciprocal_math:
148+
ReciprocalMath = true;
149+
break;
150+
case options::OPT_fno_reciprocal_math:
151+
ReciprocalMath = false;
152+
break;
146153
}
147154

148155
// If we handled this option claim it
@@ -166,6 +173,9 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
166173

167174
if (AssociativeMath && !SignedZeros)
168175
CmdArgs.push_back("-mreassociate");
176+
177+
if (ReciprocalMath)
178+
CmdArgs.push_back("-freciprocal-math");
169179
}
170180

171181
void Flang::ConstructJob(Compilation &C, const JobAction &JA,

flang/include/flang/Frontend/LangOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ LANGOPT(ApproxFunc, 1, false)
3131
LANGOPT(NoSignedZeros, 1, false)
3232
/// Allow reassociation transformations for floating-point instructions
3333
LANGOPT(AssociativeMath, 1, false)
34+
/// Allow division operations to be reassociated
35+
LANGOPT(ReciprocalMath, 1, false)
3436

3537
#undef LANGOPT
3638
#undef ENUM_LANGOPT

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,12 @@ static bool parseFloatingPointArgs(CompilerInvocation &invoc,
726726
opts.AssociativeMath = true;
727727
}
728728

729+
if (const llvm::opt::Arg *a =
730+
args.getLastArg(clang::driver::options::OPT_freciprocal_math)) {
731+
diags.Report(diagUnimplemented) << a->getOption().getName();
732+
opts.ReciprocalMath = true;
733+
}
734+
729735
return true;
730736
}
731737

flang/test/Driver/driver-help-hidden.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
! CHECK-NEXT: -fno-signed-zeros Allow optimizations that ignore the sign of floating point zeros
4949
! CHECK-NEXT: -fopenacc Enable OpenACC
5050
! CHECK-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
51+
! CHECK-NEXT: -freciprocal-math Allow division operations to be reassociated
5152
! CHECK-NEXT: -fsyntax-only Run the preprocessor, parser and semantic analysis stages
5253
! CHECK-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
5354
! CHECK-NEXT: -help Display available options

flang/test/Driver/driver-help.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
! HELP-NEXT: -fno-signed-zeros Allow optimizations that ignore the sign of floating point zeros
4747
! HELP-NEXT: -fopenacc Enable OpenACC
4848
! HELP-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
49+
! HELP-NEXT: -freciprocal-math Allow division operations to be reassociated
4950
! HELP-NEXT: -fsyntax-only Run the preprocessor, parser and semantic analysis stages
5051
! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
5152
! HELP-NEXT: -help Display available options
@@ -128,6 +129,7 @@
128129
! HELP-FC1-NEXT: -fno-signed-zeros Allow optimizations that ignore the sign of floating point zeros
129130
! HELP-FC1-NEXT: -fopenacc Enable OpenACC
130131
! HELP-FC1-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
132+
! HELP-FC1-NEXT: -freciprocal-math Allow division operations to be reassociated
131133
! HELP-FC1-NEXT: -fsyntax-only Run the preprocessor, parser and semantic analysis stages
132134
! HELP-FC1-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
133135
! HELP-FC1-NEXT: -help Display available options

flang/test/Driver/flang_fp_opts.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
! RUN: -fapprox-func \
88
! RUN: -fno-signed-zeros \
99
! RUN: -mreassociate \
10+
! RUN: -freciprocal-math \
1011
! RUN: %s 2>&1 | FileCheck %s
1112
! CHECK: ffp-contract= is not currently implemented
1213
! CHECK: menable-no-infs is not currently implemented
1314
! CHECK: menable-no-nans is not currently implemented
1415
! CHECK: fapprox-func is not currently implemented
1516
! CHECK: fno-signed-zeros is not currently implemented
1617
! CHECK: mreassociate is not currently implemented
18+
! CHECK: freciprocal-math is not currently implemented

flang/test/Driver/frontend-forwarding.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
! RUN: -fapprox-func \
1515
! RUN: -fno-signed-zeros \
1616
! RUN: -fassociative-math \
17+
! RUN: -freciprocal-math \
1718
! RUN: -mllvm -print-before-all\
1819
! RUN: -P \
1920
! RUN: | FileCheck %s
@@ -30,5 +31,6 @@
3031
! CHECK: "-fapprox-func"
3132
! CHECK: "-fno-signed-zeros"
3233
! CHECK: "-mreassociate"
34+
! CHECK: "-freciprocal-math"
3335
! CHECK: "-fconvert=little-endian"
3436
! CHECK: "-mllvm" "-print-before-all"

0 commit comments

Comments
 (0)