]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Cleanup flag_complex_method further
authorRichard Biener <rguenther@suse.de>
Mon, 20 Oct 2025 08:20:18 +0000 (10:20 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 27 Oct 2025 13:39:29 +0000 (14:39 +0100)
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.

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
gcc/common.opt
gcc/fortran/options.cc
gcc/go/go-lang.cc
gcc/lto/lto-lang.cc
gcc/opts.cc
gcc/testsuite/gcc.dg/complex-8.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/complex-9.c [new file with mode: 0644]

index 7bec3f10599725520cf85b79100b84f1845d4cd7..b7dc8ceae82063befea562434b9cc2a7b0f3f6e7 100644 (file)
@@ -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.  */
index 9b8fbf6a684538f15357aeb8e375aac57523ebe0..92b0d4d931bdcb3654f1265d392e0c5265adf402 100644 (file)
@@ -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
index 21839ef4a4f99e2f4f206b59066037e14b324243..59c64624b51d57dea2e616fa3e58c0061738d8ae 100644 (file)
@@ -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
index 0c9c9ce358449a6e5b6d48d76a077ab95d7823fe..0222b8abf81ae190a3d7f907615bb872733be828 100644 (file)
@@ -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;
index e41b548b39831e58ce27b4605ca48be54c9c6bd2..3e71a8fce74d933b67ba92a4ebab8a935cfed281 100644 (file)
@@ -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
index 21ac6b566e0bd71cd25bf3239467306a5ac0885b..ceb1e0f445b15ff23fc57b7cc8f67123de228244 100644 (file)
@@ -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 (file)
index 0000000..ea20adf
--- /dev/null
@@ -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 (file)
index 0000000..413c507
--- /dev/null
@@ -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" } } */