public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCHv2][PR 56727] Bypass PLT for recursive calls
@ 2017-07-02  7:55 Yuri Gribov
  0 siblings, 0 replies; only message in thread
From: Yuri Gribov @ 2017-07-02  7:55 UTC (permalink / raw)
  To: GCC Patches; +Cc: Jan Hubicka, Jakub Jelinek, Alexander Monakov

[-- Attachment #1: Type: text/plain, Size: 143 bytes --]

Hi all,

This is a new version of previous patch
(https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00020.html), fixed
after Rainer's remarks.

-Y

[-- Attachment #2: pr56727-2.patch --]
[-- Type: application/octet-stream, Size: 3158 bytes --]

diff -rupN gcc/gcc/ipa-visibility.c gcc-56727/gcc/ipa-visibility.c
--- gcc/gcc/ipa-visibility.c	2017-06-29 21:14:57.000000000 +0200
+++ gcc-56727/gcc/ipa-visibility.c	2017-07-01 22:03:34.000000000 +0200
@@ -83,6 +83,7 @@ along with GCC; see the file COPYING3.  
 #include "cgraph.h"
 #include "calls.h"
 #include "varasm.h"
+#include "ipa-utils.h"
 
 /* Return true when NODE can not be local. Worker for cgraph_local_node_p.  */
 
@@ -617,6 +618,36 @@ function_and_variable_visibility (bool w
   /* All aliases should be procssed at this point.  */
   gcc_checking_assert (!alias_pairs || !alias_pairs->length ());
 
+  FOR_EACH_DEFINED_FUNCTION (node)
+    {
+      if (node->get_availability () != AVAIL_INTERPOSABLE
+          || node->can_be_discarded_p ()
+          || node->has_aliases_p ())
+        continue;
+
+      cgraph_node *alias = 0;
+      for (cgraph_edge *e = node->callees; e; e = e->next_callee)
+        {
+          /* Recursive function calls usually can't be interposed.  */
+
+          if (!e->recursive_p ())
+            continue;
+
+          if (!alias)
+            { 
+              alias = dyn_cast<cgraph_node *> (node->noninterposable_alias ());
+              gcc_assert (alias && alias != node);
+            }
+
+          e->redirect_callee (alias);
+          if (gimple_has_body_p (e->caller->decl))
+            { 
+              push_cfun (DECL_STRUCT_FUNCTION (e->caller->decl));
+              e->redirect_call_stmt_to_callee ();
+              pop_cfun (); 
+            }
+        }
+    }
   FOR_EACH_FUNCTION (node)
     {
       int flags = flags_from_decl_or_type (node->decl);
diff -rupN gcc/gcc/testsuite/gcc.dg/pr56727-1.c gcc-56727/gcc/testsuite/gcc.dg/pr56727-1.c
--- gcc/gcc/testsuite/gcc.dg/pr56727-1.c	1970-01-01 01:00:00.000000000 +0100
+++ gcc-56727/gcc/testsuite/gcc.dg/pr56727-1.c	2017-07-02 08:35:27.000000000 +0200
@@ -0,0 +1,23 @@
+/* { dg-do compile { target fpic } } */
+/* { dg-options "-O2 -fPIC" } */
+/* { dg-final { scan-assembler-not "@(PLT|plt)" { target i?86-*-* x86_64-*-* powerpc*-*-* } } } */
+
+#define define_func(type) \
+  void f_ ## type (type b) { f_ ## type (0); } \
+  void __attribute__((noinline, noclone)) f_noinline_ ## type (type b) \
+  { f_noinline_ ## type (0); }
+
+define_func(char)
+define_func(short)
+define_func(int)
+define_func(long)
+
+int foo(int n)
+{
+  return (n == 1 || n == 2) ? 1 : foo(n-1) * foo(n-2);
+}
+
+int __attribute__((noinline, noclone)) foo_noinline(int n)
+{
+  return (n == 1 || n == 2) ? 1 : foo_noinline(n-1) * foo_noinline(n-2);
+}
diff -rupN gcc/gcc/testsuite/gcc.dg/pr56727-2.c gcc-56727/gcc/testsuite/gcc.dg/pr56727-2.c
--- gcc/gcc/testsuite/gcc.dg/pr56727-2.c	1970-01-01 01:00:00.000000000 +0100
+++ gcc-56727/gcc/testsuite/gcc.dg/pr56727-2.c	2017-07-02 08:35:18.000000000 +0200
@@ -0,0 +1,16 @@
+/* { dg-do compile { target fpic } } */
+/* { dg-options "-O2 -fPIC" } */
+/* { dg-final { scan-assembler "@(PLT|plt)" { target i?86-*-* x86_64-*-* powerpc*-*-* } } } */
+
+__attribute__((noinline, noclone))
+void f (short b)
+{
+  f (0);
+}
+
+static void g (short) __attribute__ ((alias ("f")));
+
+void h ()
+{
+  g (0);
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-07-02  7:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-02  7:55 [PATCHv2][PR 56727] Bypass PLT for recursive calls Yuri Gribov

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).