re PR middle-end/56727 (Recursive call goes through the PLT unnecessarily)
authorJan Hubicka <hubicka@ucw.cz>
Sat, 11 Feb 2017 17:56:02 +0000 (18:56 +0100)
committerJan Hubicka <hubicka@gcc.gnu.org>
Sat, 11 Feb 2017 17:56:02 +0000 (17:56 +0000)
PR tree-ssa/56727
* gcc.dg/tree-ssa/pr56727.c: New testcase.
* ipa-utils.c (recursive_call_p): Be more careful about interposition.

From-SVN: r245359

gcc/ChangeLog
gcc/ipa-utils.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr56727.c [new file with mode: 0644]

index 424fb4f6f299b09f977b796777ca48b4de47869b..969fccfe9ee090ae8718f73fdf94ad0f5450550d 100644 (file)
@@ -1,3 +1,8 @@
+2017-02-11  Jan Hubicka  <hubicka@ucw.cz>
+
+       PR tree-ssa/56727
+       * gcc.dg/tree-ssa/pr56727.c: New testcase.
+
 2017-02-11  Jan Hubicka  <hubicka@ucw.cz>
 
        PR ipa/79224
index fc1ae1e19d1c4eb2998d01c331437aca045c6787..98a4f11d9bfb5ddb6ec49a4a08639690a91779da 100644 (file)
@@ -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);
-
-  return dest_node->semantically_equivalent_p (cnode);
+  ipa_ref *alias;
+  enum availability avail;
+
+  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;
 }
index 7a5abd8a3337dfbd52cd6e9a08207b9e93b65f0b..a6afdf5d0a0bc8cfbd8cefb290414434325d1153 100644 (file)
@@ -1,3 +1,8 @@
+2017-02-11  Jan Hubicka  <hubicka@ucw.cz>
+
+       PR tree-ssa/56727
+       * gcc.dg/tree-ssa/pr56727.c: New testcase.
+
 2017-02-10  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/79457
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr56727.c b/gcc/testsuite/gcc.dg/tree-ssa/pr56727.c
new file mode 100644 (file)
index 0000000..eaf8b5c
--- /dev/null
@@ -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" } } */