This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, PR 40570] Do not create cycles of inlined nodes when inlining functions called once


Hi,

I guess the subject says it all.  This fixes PR 40570 by not inlining
a function into itself, even when it is its own only caller.

Bootstrapped and tested on x86_64-linux but apart from an approval in
general, I would still like Honza to confirm this is indeed a correct
fix before committing.

Thanks,

Martin



2009-07-28  Martin Jambor  <mjambor@suse.cz>

	* ipa-inline.c (cgraph_decide_inlining): Watch out for dead single
	use inlining loops.

	* testsuite/gcc.c-torture/compile/pr40570.c: New test.


Index: icln/gcc/ipa-inline.c
===================================================================
--- icln.orig/gcc/ipa-inline.c
+++ icln/gcc/ipa-inline.c
@@ -1227,6 +1227,7 @@ cgraph_decide_inlining (void)
 	      && !node->needed
 	      && node->local.inlinable
 	      && node->callers->inline_failed
+	      && node->callers->caller->global.inlined_to != node
 	      && !gimple_call_cannot_inline_p (node->callers->call_stmt)
 	      && !DECL_EXTERNAL (node->decl)
 	      && !DECL_COMDAT (node->decl))
Index: icln/gcc/testsuite/gcc.c-torture/compile/pr40570.c
===================================================================
--- /dev/null
+++ icln/gcc/testsuite/gcc.c-torture/compile/pr40570.c
@@ -0,0 +1,19 @@
+static int foo(int i);
+
+static int bar(int i) { foo(i); }
+
+static int foo(int i)
+{
+  int j;
+  if (j)
+    FOO(j);
+  return bar(i);
+}
+
+int baz()
+{
+  foo(0);
+  if (baz())
+    return 1;
+  return 0;
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]