public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Martin Jambor <jamborm@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-7593] ipa-cp: Avoid adjusting references through self-recursion (PR 104813)
Date: Thu, 10 Mar 2022 13:56:24 +0000 (GMT)	[thread overview]
Message-ID: <20220310135624.3F9C6385841D@sourceware.org> (raw)

https://gcc.gnu.org/g:e671e48e352ee278d816d4633146208807a0e403

commit r12-7593-ge671e48e352ee278d816d4633146208807a0e403
Author: Martin Jambor <mjambor@suse.cz>
Date:   Thu Mar 10 14:49:23 2022 +0100

    ipa-cp: Avoid adjusting references through self-recursion (PR 104813)
    
    When writing the patch that downgrades address-taken references to
    load references when IPA-CP can prove that all uses of the taken
    address ends up in loads, I unfortunately did not take into account
    that find_more_scalar_values_for_callers_subset now happily adds
    self-recursive edges to the set of callers which should be immediately
    redirected (originally recursion was meant to be handled as edge
    redirection in a second pass over the SCC).
    
    The code as it is can now decrement the referece counters too many
    times.  This can remedied by removing self-recursive edges earlier, we
    already do it because of thunk expansion issues, and so this patch
    does exactly that.
    
    gcc/ChangeLog:
    
    2022-03-07  Martin Jambor  <mjambor@suse.cz>
    
            PR ipa/104813
            * ipa-cp.cc (create_specialized_node): Move removal of
            self-recursive calls from callers vector before refrence
            adjustments.
    
    gcc/testsuite/ChangeLog:
    
    2022-03-07  Martin Jambor  <mjambor@suse.cz>
    
            PR ipa/104813
            * gcc.dg/ipa/pr104813.c: New test.

Diff:
---
 gcc/ipa-cp.cc                       | 20 ++++++++++----------
 gcc/testsuite/gcc.dg/ipa/pr104813.c | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 10 deletions(-)

diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc
index 453e9c93cc3..18047c209a8 100644
--- a/gcc/ipa-cp.cc
+++ b/gcc/ipa-cp.cc
@@ -5099,6 +5099,16 @@ create_specialized_node (struct cgraph_node *node,
   else
     new_adjustments = NULL;
 
+  auto_vec<cgraph_edge *, 2> self_recursive_calls;
+  for (i = callers.length () - 1; i >= 0; i--)
+    {
+      cgraph_edge *cs = callers[i];
+      if (cs->caller == node)
+	{
+	  self_recursive_calls.safe_push (cs);
+	  callers.unordered_remove (i);
+	}
+    }
   replace_trees = cinfo ? vec_safe_copy (cinfo->tree_map) : NULL;
   for (i = 0; i < count; i++)
     {
@@ -5129,16 +5139,6 @@ create_specialized_node (struct cgraph_node *node,
       if (replace_map)
 	vec_safe_push (replace_trees, replace_map);
     }
-  auto_vec<cgraph_edge *, 2> self_recursive_calls;
-  for (i = callers.length () - 1; i >= 0; i--)
-    {
-      cgraph_edge *cs = callers[i];
-      if (cs->caller == node)
-	{
-	  self_recursive_calls.safe_push (cs);
-	  callers.unordered_remove (i);
-	}
-    }
 
   unsigned &suffix_counter = clone_num_suffixes->get_or_insert (
 			       IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (
diff --git a/gcc/testsuite/gcc.dg/ipa/pr104813.c b/gcc/testsuite/gcc.dg/ipa/pr104813.c
new file mode 100644
index 00000000000..34f413e3823
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/pr104813.c
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-options "-O3"  } */
+
+int a, b, c, d, *e;
+void f(int h) {
+  if (b) {
+    int g;
+    while (g++)
+      d = *e;
+    e++;
+  }
+}
+static void i();
+static void j(int *h, int k, int *l) {
+  if (c) {
+    int *o = h, m;
+    f(*l);
+    i(m);
+    j(o, 1, o);
+    for (;;)
+      ;
+  }
+}
+void i() {
+  int *n = &a;
+  while (1)
+    j(n, 1, n);
+}
+int main() {
+  j(&a, 0, &a);
+  return 0;
+}


                 reply	other threads:[~2022-03-10 13:56 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=20220310135624.3F9C6385841D@sourceware.org \
    --to=jamborm@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).