PR122325 reports that -ffast-math no longer enables -fcx-limited-range.
This is due to the weird handling of flag_default_complex_method which
the following simply removes. Frontends that wish to impose a default
evaluation method that is not -fcx-fortran-rules (the current default
of flag_default_complex_method) need to imposed that in ther
init_options_struct langhook which those requesting C std rules already
do and I'm adding that for the fortran frontend, explicitly requesting
fortran rules.
Bootstrapped and tested on x86_64-unknown-linux-gnu. OK for trunk?
Thanks,
Richard.
PR middle-end/122325
gcc/
* common.opt (flag_default_complex_method): Remove.
* opts.cc (init_options_struct): Default to fortran rules
for complex evaluations.
(finish_options): Remove (re-)instantiating of the frontend
default of the complex evaluation method.
gcc/c-family/
* c-opts.cc (c_common_init_options_struct): Remove set of
flag_default_complex_method.
gcc/go/
* go-lang.cc (go_langhook_init_options_struct): Remove set of
flag_default_complex_method.
gcc/lto/
* lto-lang.cc (lto_init_options_struct): Remove set of
flag_default_complex_method.
gcc/fortran/
* options.cc (gfc_init_options_struct): Set flag_complex_method
to fortran rules.
gcc/testsuite/
* gcc.dg/complex-8.c: New testcase.
* gcc.dg/complex-9.c: Likewise.
---
gcc/c-family/c-opts.cc | 1 -
gcc/common.opt | 3 ---
gcc/fortran/options.cc | 1 +
gcc/go/go-lang.cc | 1 -
gcc/lto/lto-lang.cc | 1 -
gcc/opts.cc | 7 +++----
gcc/testsuite/gcc.dg/complex-8.c | 13 +++++++++++++
gcc/testsuite/gcc.dg/complex-9.c | 13 +++++++++++++
8 files changed, 30 insertions(+), 10 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/complex-8.c
create mode 100644 gcc/testsuite/gcc.dg/complex-9.c
diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
index 7bec3f10599..b7dc8ceae82 100644
--- a/gcc/c-family/c-opts.cc
+++ b/gcc/c-family/c-opts.cc
@@ -230,7 +230,6 @@ c_common_init_options_struct (struct gcc_options *opts)
/* By default, C99-like requirements for complex multiply and divide. */
opts->x_flag_complex_method = 2;
- opts->x_flag_default_complex_method = opts->x_flag_complex_method;
}
/* Common initialization before calling option handlers. */
diff --git a/gcc/common.opt b/gcc/common.opt
index 9b8fbf6a684..92b0d4d931b 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -53,9 +53,6 @@ bool in_lto_p = false
Variable
enum incremental_link flag_incremental_link = INCREMENTAL_LINK_NONE
-Variable
-int flag_default_complex_method = 1
-
; Language specific warning pass for unused results.
Variable
bool flag_warn_unused_result = false
diff --git a/gcc/fortran/options.cc b/gcc/fortran/options.cc
index 21839ef4a4f..59c64624b51 100644
--- a/gcc/fortran/options.cc
+++ b/gcc/fortran/options.cc
@@ -133,6 +133,7 @@ gfc_init_options_struct (struct gcc_options *opts)
opts->frontend_set_flag_errno_math = true;
opts->x_flag_associative_math = -1;
opts->frontend_set_flag_associative_math = true;
+ opts->x_flag_complex_method = 1;
}
/* Get ready for options handling. Keep in sync with
diff --git a/gcc/go/go-lang.cc b/gcc/go/go-lang.cc
index 0c9c9ce3584..0222b8abf81 100644
--- a/gcc/go/go-lang.cc
+++ b/gcc/go/go-lang.cc
@@ -173,7 +173,6 @@ go_langhook_init_options_struct (struct gcc_options *opts)
/* Default to avoiding range issues for complex multiply and
divide. */
opts->x_flag_complex_method = 2;
- opts->x_flag_default_complex_method = opts->x_flag_complex_method;
/* The builtin math functions should not set errno. */
opts->x_flag_errno_math = 0;
diff --git a/gcc/lto/lto-lang.cc b/gcc/lto/lto-lang.cc
index e41b548b398..3e71a8fce74 100644
--- a/gcc/lto/lto-lang.cc
+++ b/gcc/lto/lto-lang.cc
@@ -841,7 +841,6 @@ lto_init_options_struct (struct gcc_options *opts)
safe choice. This will pessimize Fortran code with LTO unless
people specify a complex method manually or use -ffast-math. */
opts->x_flag_complex_method = 2;
- opts->x_flag_default_complex_method = opts->x_flag_complex_method;
}
/* Handle command-line option SCODE. If the option takes an argument, it is
diff --git a/gcc/opts.cc b/gcc/opts.cc
index 21ac6b566e0..ceb1e0f445b 100644
--- a/gcc/opts.cc
+++ b/gcc/opts.cc
@@ -454,6 +454,9 @@ init_options_struct (struct gcc_options *opts, struct
gcc_options *opts_set)
/* Some targets have ABI-specified unwind tables. */
opts->x_flag_unwind_tables = targetm_common.unwind_tables_default;
+ /* Languages not explicitly specifying a default get fortran rules. */
+ opts->x_flag_complex_method = 1;
+
/* Some targets have other target-specific initialization. */
targetm_common.option_init_struct (opts);
}
@@ -1393,10 +1396,6 @@ finish_options (struct gcc_options *opts, struct
gcc_options *opts_set,
|| opts->x_flag_peel_loops
|| opts->x_optimize >= 3);
- /* Use a frontend provided default for the complex eval method. */
- if (!opts_set->x_flag_complex_method)
- opts->x_flag_complex_method = opts->x_flag_default_complex_method;
-
/* Use -fvect-cost-model=cheap instead of -fvect-cost-mode=very-cheap
by default with explicit -ftree-{loop,slp}-vectorize. */
if (opts->x_optimize == 2
diff --git a/gcc/testsuite/gcc.dg/complex-8.c b/gcc/testsuite/gcc.dg/complex-8.c
new file mode 100644
index 00000000000..ea20adf2485
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/complex-8.c
@@ -0,0 +1,13 @@
+/* PR tree-optimization/122325. */
+
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-cplxlower" } */
+/* { dg-require-effective-target double64 } */
+
+__complex double
+foo (__complex double a, __complex double b)
+{
+ return a / b;
+}
+
+/* { dg-final { scan-tree-dump-times "__(?:gnu_)?divdc3" 1 "cplxlower1" } } */
diff --git a/gcc/testsuite/gcc.dg/complex-9.c b/gcc/testsuite/gcc.dg/complex-9.c
new file mode 100644
index 00000000000..413c507fd25
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/complex-9.c
@@ -0,0 +1,13 @@
+/* PR tree-optimization/122325. */
+
+/* { dg-do compile } */
+/* { dg-options "-O2 -ffast-math -fdump-tree-cplxlower" } */
+/* { dg-require-effective-target double64 } */
+
+__complex double
+foo (__complex double a, __complex double b)
+{
+ return a / b;
+}
+
+/* { dg-final { scan-tree-dump-not "__(?:gnu_)?divdc3" "cplxlower1" } } */
--
2.51.0