public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-1600] target/105459 - allow delayed target option node fixup
Date: Mon, 11 Jul 2022 09:22:17 +0000 (GMT)	[thread overview]
Message-ID: <20220711092217.3EF3B3858412@sourceware.org> (raw)

https://gcc.gnu.org/g:4c94382a132a4b2b9d020806549a006fa6764d1b

commit r13-1600-g4c94382a132a4b2b9d020806549a006fa6764d1b
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Jul 1 14:11:35 2022 +0200

    target/105459 - allow delayed target option node fixup
    
    The following avoids the need to massage the target optimization
    node at WPA time when we fixup the optimization node, copying
    FP related flags from callee to caller.  The target is already
    set up to fixup, but that only works when not switching between
    functions.  After fixing that the fixup is then done at LTRANS
    time when materializing the function.
    
    2022-07-01  Richard Biener  <rguenthert@suse.de>
    
            PR target/105459
            * config/i386/i386-options.cc (ix86_set_current_function):
            Rebuild the target optimization node whenever necessary,
            not only when the optimization node didn't change.
    
            * gcc.dg/lto/pr105459_0.c: New testcase.

Diff:
---
 gcc/config/i386/i386-options.cc       | 32 +++++++++++++-------------------
 gcc/testsuite/gcc.dg/lto/pr105459_0.c | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 19 deletions(-)

diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc
index e11f68186f5..acb2291e70f 100644
--- a/gcc/config/i386/i386-options.cc
+++ b/gcc/config/i386/i386-options.cc
@@ -3232,28 +3232,22 @@ ix86_set_current_function (tree fndecl)
   if (new_tree == NULL_TREE)
     new_tree = target_option_default_node;
 
-  if (old_tree != new_tree)
+  bool fp_flag_change
+    = (flag_unsafe_math_optimizations
+       != TREE_TARGET_OPTION (new_tree)->x_ix86_unsafe_math_optimizations
+       || (flag_excess_precision
+	   != TREE_TARGET_OPTION (new_tree)->x_ix86_excess_precision));
+  if (old_tree != new_tree || fp_flag_change)
     {
       cl_target_option_restore (&global_options, &global_options_set,
 				TREE_TARGET_OPTION (new_tree));
-      if (TREE_TARGET_GLOBALS (new_tree))
-	restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
-      else if (new_tree == target_option_default_node)
-	restore_target_globals (&default_target_globals);
-      else
-	TREE_TARGET_GLOBALS (new_tree) = save_target_globals_default_opts ();
-    }
-  else if (flag_unsafe_math_optimizations
-	   != TREE_TARGET_OPTION (new_tree)->x_ix86_unsafe_math_optimizations
-	   || (flag_excess_precision
-	       != TREE_TARGET_OPTION (new_tree)->x_ix86_excess_precision))
-    {
-      cl_target_option_restore (&global_options, &global_options_set,
-				TREE_TARGET_OPTION (new_tree));
-      ix86_excess_precision = flag_excess_precision;
-      ix86_unsafe_math_optimizations = flag_unsafe_math_optimizations;
-      DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_tree
-	= build_target_option_node (&global_options, &global_options_set);
+      if (fp_flag_change)
+	{
+	  ix86_excess_precision = flag_excess_precision;
+	  ix86_unsafe_math_optimizations = flag_unsafe_math_optimizations;
+	  DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_tree
+	    = build_target_option_node (&global_options, &global_options_set);
+	}
       if (TREE_TARGET_GLOBALS (new_tree))
 	restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
       else if (new_tree == target_option_default_node)
diff --git a/gcc/testsuite/gcc.dg/lto/pr105459_0.c b/gcc/testsuite/gcc.dg/lto/pr105459_0.c
new file mode 100644
index 00000000000..c799e6ef23d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/pr105459_0.c
@@ -0,0 +1,35 @@
+/* { dg-lto-do link } */
+/* { dg-lto-options { { -flto -O1 } } } */
+
+double m;
+int n;
+
+__attribute__ ((optimize ("-funsafe-math-optimizations")))
+void
+bar (int x)
+{
+  n = x;
+  m = n;
+}
+
+__attribute__ ((flatten))
+void
+foo (int x)
+{
+  bar (x);
+}
+
+void
+quux (void)
+{
+  ++n;
+}
+
+int
+main (void)
+{
+  foo (0);
+  quux ();
+
+  return 0;
+}


                 reply	other threads:[~2022-07-11  9:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220711092217.3EF3B3858412@sourceware.org \
    --to=rguenth@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).