Skip to content

Commit b5b8a8c

Browse files
committed
[flang] Add -f[no-]signed-zeros
Only add the option processing and store the result. No attributes are added to FIR yet. Differential Revision: https://reviews.llvm.org/D137328
1 parent 36b37a1 commit b5b8a8c

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
@@ -1902,7 +1902,7 @@ defm finite_math_only : BoolFOption<"finite-math-only",
19021902
NegFlag<SetFalse>>;
19031903
defm signed_zeros : BoolFOption<"signed-zeros",
19041904
LangOpts<"NoSignedZero">, DefaultFalse,
1905-
NegFlag<SetTrue, [CC1Option], "Allow optimizations that ignore the sign of floating point zeros",
1905+
NegFlag<SetTrue, [CC1Option, FC1Option, FlangOption], "Allow optimizations that ignore the sign of floating point zeros",
19061906
[cl_no_signed_zeros.KeyPath, funsafe_math_optimizations.KeyPath]>,
19071907
PosFlag<SetFalse>>;
19081908
def fhonor_nans : Flag<["-"], "fhonor-nans">, Group<f_Group>;

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
8686
bool HonorINFs = true;
8787
bool HonorNaNs = true;
8888
bool ApproxFunc = false;
89+
bool SignedZeros = true;
8990

9091
if (const Arg *A = Args.getLastArg(options::OPT_ffp_contract)) {
9192
const StringRef Val = A->getValue();
@@ -129,6 +130,12 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
129130
case options::OPT_fno_approx_func:
130131
ApproxFunc = false;
131132
break;
133+
case options::OPT_fsigned_zeros:
134+
SignedZeros = true;
135+
break;
136+
case options::OPT_fno_signed_zeros:
137+
SignedZeros = false;
138+
break;
132139
}
133140

134141
// If we handled this option claim it
@@ -146,6 +153,9 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
146153

147154
if (ApproxFunc)
148155
CmdArgs.push_back("-fapprox-func");
156+
157+
if (!SignedZeros)
158+
CmdArgs.push_back("-fno-signed-zeros");
149159
}
150160

151161
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
@@ -27,6 +27,8 @@ LANGOPT(NoHonorInfs, 1, false)
2727
LANGOPT(NoHonorNaNs, 1, false)
2828
/// Allow math functions to be replaced with an approximately equivalent calculation
2929
LANGOPT(ApproxFunc, 1, false)
30+
/// Allow optimizations that ignore the sign of floating point zeros
31+
LANGOPT(NoSignedZeros, 1, false)
3032

3133
#undef LANGOPT
3234
#undef ENUM_LANGOPT

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,12 @@ static bool parseFloatingPointArgs(CompilerInvocation &invoc,
714714
opts.ApproxFunc = true;
715715
}
716716

717+
if (const llvm::opt::Arg *a =
718+
args.getLastArg(clang::driver::options::OPT_fno_signed_zeros)) {
719+
diags.Report(diagUnimplemented) << a->getOption().getName();
720+
opts.NoSignedZeros = true;
721+
}
722+
717723
return true;
718724
}
719725

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
! CHECK-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
4646
! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
4747
! CHECK-NEXT: -fno-integrated-as Disable the integrated assembler
48+
! CHECK-NEXT: -fno-signed-zeros Allow optimizations that ignore the sign of floating point zeros
4849
! CHECK-NEXT: -fopenacc Enable OpenACC
4950
! CHECK-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
5051
! CHECK-NEXT: -fsyntax-only Run the preprocessor, parser and semantic analysis stages

flang/test/Driver/driver-help.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
! HELP-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
4444
! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
4545
! HELP-NEXT: -fno-integrated-as Disable the integrated assembler
46+
! HELP-NEXT: -fno-signed-zeros Allow optimizations that ignore the sign of floating point zeros
4647
! HELP-NEXT: -fopenacc Enable OpenACC
4748
! HELP-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
4849
! HELP-NEXT: -fsyntax-only Run the preprocessor, parser and semantic analysis stages
@@ -124,6 +125,7 @@
124125
! HELP-FC1-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
125126
! HELP-FC1-NEXT: -fno-debug-pass-manager Disables debug printing for the new pass manager
126127
! HELP-FC1-NEXT: -fno-reformat Dump the cooked character stream in -E mode
128+
! HELP-FC1-NEXT: -fno-signed-zeros Allow optimizations that ignore the sign of floating point zeros
127129
! HELP-FC1-NEXT: -fopenacc Enable OpenACC
128130
! HELP-FC1-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
129131
! HELP-FC1-NEXT: -fsyntax-only Run the preprocessor, parser and semantic analysis stages

flang/test/Driver/flang_fp_opts.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
! RUN: -menable-no-infs \
66
! RUN: -menable-no-nans \
77
! RUN: -fapprox-func \
8+
! RUN: -fno-signed-zeros \
89
! RUN: %s 2>&1 | FileCheck %s
910
! CHECK: ffp-contract= is not currently implemented
1011
! CHECK: menable-no-infs is not currently implemented
1112
! CHECK: menable-no-nans is not currently implemented
1213
! CHECK: fapprox-func is not currently implemented
14+
! CHECK: fno-signed-zeros is not currently implemented

flang/test/Driver/frontend-forwarding.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
! RUN: -fno-honor-infinities \
1313
! RUN: -fno-honor-nans \
1414
! RUN: -fapprox-func \
15+
! RUN: -fno-signed-zeros \
1516
! RUN: -mllvm -print-before-all\
1617
! RUN: -P \
1718
! RUN: | FileCheck %s
@@ -26,5 +27,6 @@
2627
! CHECK: "-menable-no-infs"
2728
! CHECK: "-menable-no-nans"
2829
! CHECK: "-fapprox-func"
30+
! CHECK: "-fno-signed-zeros"
2931
! CHECK: "-fconvert=little-endian"
3032
! CHECK: "-mllvm" "-print-before-all"

0 commit comments

Comments
 (0)