From: "Martin Liška" <mliska@suse.cz>
To: Richard Biener <richard.guenther@gmail.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
Jakub Jelinek <jakub@redhat.com>, Michael Matz <matz@suse.de>
Subject: [PATCH] flag_complex_method: support optimize attribute
Date: Mon, 6 Sep 2021 13:37:46 +0200 [thread overview]
Message-ID: <766332d7-388b-3697-9a7b-1933c030a966@suse.cz> (raw)
In-Reply-To: <CAFiYyc0Kej7BhwoMKuPzPuh9oVtzZPWR=vFK8T5cMgdOmLkD+A@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1666 bytes --]
On 8/26/21 13:04, Richard Biener wrote:
> Yes, and that flag_complex_method is initialized via the langhook
> mentioned, for example
> c-family/c-opts.c has
>
> /* Initialize options structure OPTS. */
> void
> c_common_init_options_struct (struct gcc_options *opts)
> {
> opts->x_flag_exceptions = c_dialect_cxx ();
> opts->x_warn_pointer_arith = c_dialect_cxx ();
> opts->x_warn_write_strings = c_dialect_cxx ();
> opts->x_flag_warn_unused_result = true;
>
> /* By default, C99-like requirements for complex multiply and divide. */
> opts->x_flag_complex_method = 2;
> }
>
> so an attempt to "cancel" a command-line option that adjusted any of
> the above will not
> work because we're not re-initializing global_options appropriately.
> But maybe we can
> just do that? That is, call
>
> /* Initialize global options structures; this must be repeated for
> each structure used for parsing options. */
> init_options_struct (&global_options, &global_options_set);
> lang_hooks.init_options_struct (&global_options);
>
> and
>
> /* Perform language-specific options initialization. */
> lang_hooks.init_options (save_decoded_options_count, save_decoded_options);
>
> as done by toplev.c? Or if we do not want to do that store that state away
> to an 'initialized_options/initialized_options_set' set of vars we can
> copy from?
Hello.
I think the proper fix is handling the flag_complex_method-related options in finish_options.
Doing that, we can see 'optimize' pragma works with the current master.
Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Ready to be installed?
Thanks,
Martin
[-- Attachment #2: 0001-flag_complex_method-support-optimize-attribute.patch --]
[-- Type: text/x-patch, Size: 2655 bytes --]
From 203451d5ea5352e75da27dcf8259cc8dd7880512 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Fri, 3 Sep 2021 10:53:00 +0200
Subject: [PATCH] flag_complex_method: support optimize attribute
gcc/ChangeLog:
* opts.c (finish_options): Move flag_complex_method setting
from ...
* toplev.c (process_options): ... here.
gcc/testsuite/ChangeLog:
* gcc.c-torture/compile/attr-complex-method.c: New test.
---
gcc/opts.c | 8 ++++++++
.../gcc.c-torture/compile/attr-complex-method.c | 10 ++++++++++
gcc/toplev.c | 8 --------
3 files changed, 18 insertions(+), 8 deletions(-)
create mode 100644 gcc/testsuite/gcc.c-torture/compile/attr-complex-method.c
diff --git a/gcc/opts.c b/gcc/opts.c
index e0501551ef5..2ac1a932f38 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -1323,6 +1323,14 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
= (opts->x_flag_unroll_loops
|| opts->x_flag_peel_loops
|| opts->x_optimize >= 3);
+
+ /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
+ if (opts->x_flag_cx_limited_range)
+ flag_complex_method = 0;
+
+ /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
+ if (opts->x_flag_cx_fortran_rules)
+ flag_complex_method = 1;
}
#define LEFT_COLUMN 27
diff --git a/gcc/testsuite/gcc.c-torture/compile/attr-complex-method.c b/gcc/testsuite/gcc.c-torture/compile/attr-complex-method.c
new file mode 100644
index 00000000000..f08b72e273f
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/attr-complex-method.c
@@ -0,0 +1,10 @@
+/* { dg-additional-options "-fdump-tree-optimized" } */
+
+#pragma GCC optimize "-fcx-limited-range"
+
+void do_div (_Complex double *a, _Complex double *b)
+{
+ *a = *b / (4.0 - 5.0fi);
+}
+
+/* { dg-final { scan-tree-dump-not "__divdc3" "optimized" } } */
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 14d1335e79e..e1688aae724 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -1695,14 +1695,6 @@ process_options (void)
flag_stack_check = NO_STACK_CHECK;
}
- /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
- if (flag_cx_limited_range)
- flag_complex_method = 0;
-
- /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
- if (flag_cx_fortran_rules)
- flag_complex_method = 1;
-
/* Targets must be able to place spill slots at lower addresses. If the
target already uses a soft frame pointer, the transition is trivial. */
if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
--
2.33.0
next prev parent reply other threads:[~2021-09-06 11:37 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-23 11:47 [PATCH] Optimize macro: make it more predictable Martin Liška
2020-11-03 13:27 ` Richard Biener
2020-11-03 13:34 ` Jakub Jelinek
2020-11-03 13:40 ` Richard Biener
2020-11-09 10:35 ` Martin Liška
2020-11-26 13:56 ` Martin Liška
2020-12-07 11:03 ` Martin Liška
2021-01-11 13:10 ` Martin Liška
2020-11-09 10:27 ` Martin Liška
2020-11-06 17:34 ` Jeff Law
2020-11-09 10:36 ` Martin Liška
2021-07-01 13:13 ` Martin Liška
2021-08-10 15:52 ` Martin Liška
2021-08-24 11:06 ` Martin Liška
2021-08-24 12:13 ` Richard Biener
2021-08-24 13:04 ` Martin Liška
2021-08-26 11:04 ` Richard Biener
2021-08-26 12:39 ` Martin Liška
2021-08-26 13:20 ` Richard Biener
2021-08-27 8:35 ` Martin Liška
2021-08-27 9:05 ` Richard Biener
2021-09-13 13:52 ` Martin Liška
2021-09-19 5:46 ` Jeff Law
2021-09-06 11:37 ` Martin Liška [this message]
2021-09-06 11:46 ` [PATCH] flag_complex_method: support optimize attribute Jakub Jelinek
2021-09-06 12:16 ` Richard Biener
2021-09-06 12:24 ` Jakub Jelinek
2021-09-07 9:42 ` Martin Liška
2021-09-13 13:32 ` Martin Liška
2021-09-19 14:45 ` Jeff Law
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=766332d7-388b-3697-9a7b-1933c030a966@suse.cz \
--to=mliska@suse.cz \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=matz@suse.de \
--cc=richard.guenther@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).