public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jan Hubicka <hubicka@ucw.cz>
To: gcc-patches@gcc.gnu.org
Subject: Avoid recursion in tree-inline.c
Date: Tue, 3 Nov 2020 11:57:15 +0100	[thread overview]
Message-ID: <20201103105715.GA26525@kam.mff.cuni.cz> (raw)

Hi,
this patch avoids recursion in tree-inline.c by producing necessary
clones early.  This avoids an ICE on overuse of AUX pointer there.

Bootstrapped/regtested x86_64-linux, comitted.
Honza

gcc/ChangeLog:

2020-11-03  Jan Hubicka  <hubicka@ucw.cz>

	PR ipa/97578
	* ipa-inline-transform.c (maybe_materialize_called_clones): New
	function.
	(inline_transform): Use it.

gcc/testsuite/ChangeLog:

2020-11-03  Jan Hubicka  <hubicka@ucw.cz>

	* gcc.c-torture/compile/pr97578.c: New test.

diff --git a/gcc/ipa-inline-transform.c b/gcc/ipa-inline-transform.c
index 4df1b7fb9ee..907a95cac5a 100644
--- a/gcc/ipa-inline-transform.c
+++ b/gcc/ipa-inline-transform.c
@@ -51,6 +51,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "ipa-modref-tree.h"
 #include "ipa-modref.h"
 #include "symtab-thunks.h"
+#include "symtab-clones.h"
 
 int ncalls_inlined;
 int nfunctions_inlined;
@@ -695,6 +696,31 @@ preserve_function_body_p (struct cgraph_node *node)
   return false;
 }
 
+/* tree-inline can not recurse; materialize all function bodie we will need
+   during inlining.  This includes inlined functions, but also called functions
+   with param manipulation because IPA param manipulation attaches debug
+   statements to PARM_DECLs of called clone.  Materialize them if needed.
+
+   FIXME: This is somehwat broken by design because it does not play well
+   with partitioning.  */
+
+static void
+maybe_materialize_called_clones (cgraph_node *node)
+{
+  for (cgraph_edge *e = node->callees; e; e = e->next_callee)
+    {
+      clone_info *info;
+
+      if (!e->inline_failed)
+	maybe_materialize_called_clones (e->callee);
+
+      cgraph_node *callee = cgraph_node::get (e->callee->decl);
+      if (callee->clone_of
+	  && (info = clone_info::get (callee)) && info->param_adjustments)
+	callee->get_untransformed_body ();
+    }
+}
+
 /* Apply inline plan to function.  */
 
 unsigned int
@@ -748,6 +774,7 @@ inline_transform (struct cgraph_node *node)
       ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = node->count;
     }
 
+  maybe_materialize_called_clones (node);
   for (e = node->callees; e; e = next)
     {
       if (!e->inline_failed)
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr97578.c b/gcc/testsuite/gcc.c-torture/compile/pr97578.c
new file mode 100644
index 00000000000..e007724fdae
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr97578.c
@@ -0,0 +1,11 @@
+int printf (const char *, ...);
+
+int a;
+static void b(int c) {
+  if (c)
+    printf("%d", a);
+}
+void e() {
+  int d = 0;
+  b(d);
+}

                 reply	other threads:[~2020-11-03 10:57 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=20201103105715.GA26525@kam.mff.cuni.cz \
    --to=hubicka@ucw.cz \
    --cc=gcc-patches@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).