diff mbox

Fix tail recursion optimization wrt interposable symbols

Message ID 20170211175946.GA16679@kam.mff.cuni.cz
State New
Headers show

Commit Message

Jan Hubicka Feb. 11, 2017, 5:59 p.m. UTC
Hi,
this patch prevents tail recurisve optimization for functions recursing over
interposable symbol with an alias.

Bootstrapped/regtested x86_64-linux, comitted.

	PR tree-ssa/56727
	* gcc.dg/tree-ssa/pr56727.c: New testcase.
	* ipa-utils.c (recursive_call_p): Be more careful about interposition.
diff mbox

Patch

Index: testsuite/gcc.dg/tree-ssa/pr56727.c
===================================================================
--- testsuite/gcc.dg/tree-ssa/pr56727.c	(revision 0)
+++ testsuite/gcc.dg/tree-ssa/pr56727.c	(working copy)
@@ -0,0 +1,16 @@ 
+/* { dg-require-alias "" } */
+/* { dg-do compile { target fpic } } *
+/* { dg-options "-O2 -fPIC -fdump-tree-optimized" } */
+void do_not_optimize(int b)
+{
+    do_not_optimize(0);
+}
+void do_optimize(int b)
+{
+    do_optimize(0);
+}
+
+void g(int b) __attribute__((alias(("do_not_optimize"))));
+
+/* { dg-final { scan-tree-dump "do_not_optimize .0" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "do_optimize .0" "optimized" } } */
Index: ipa-utils.c
===================================================================
--- ipa-utils.c	(revision 245356)
+++ ipa-utils.c	(working copy)
@@ -639,6 +639,20 @@  recursive_call_p (tree func, tree dest)
 {
   struct cgraph_node *dest_node = cgraph_node::get_create (dest);
   struct cgraph_node *cnode = cgraph_node::get_create (func);
+  ipa_ref *alias;
+  enum availability avail;
 
-  return dest_node->semantically_equivalent_p (cnode);
+  gcc_assert (!cnode->alias);
+  if (cnode != dest_node->ultimate_alias_target (&avail))
+    return false;
+  if (avail >= AVAIL_AVAILABLE)
+    return true;
+  if (!dest_node->semantically_equivalent_p (cnode))
+    return false;
+  /* If there is only one way to call the fuction or we know all of them
+     are semantically equivalent, we still can consider call recursive.  */
+  FOR_EACH_ALIAS (cnode, alias)
+    if (!dest_node->semantically_equivalent_p (alias->referring))
+      return false;
+  return true;
 }