public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Yuri Gribov <tetra2005@gmail.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Cc: Jan Hubicka <hubicka@ucw.cz>
Subject: [PATCHv2][PING^2][PR 56727] Bypass PLT for recursive calls
Date: Mon, 17 Jul 2017 07:22:00 -0000	[thread overview]
Message-ID: <CAJOtW+7RqLrkyNywgZFZ2GbintGAz6bitoAoCDYiiiiEt602_g@mail.gmail.com> (raw)

[-- 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);
+}

             reply	other threads:[~2017-07-17  7:22 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-17  7:22 Yuri Gribov [this message]
2017-07-17  9:27 ` Jan Hubicka
2017-07-18  8:27   ` Yuri Gribov
2017-07-24 12:52     ` [PATCH] Fix wrong condition in ipa-visibility.c (PR ipa/81520) Martin Liška
2017-07-24 14:06       ` Jan Hubicka
2017-07-31  8:04         ` [PATCH] Introduce TARGET_SUPPORTS_ALIASES Martin Liška
2017-07-31  9:58           ` Yuri Gribov
2017-07-31 11:22             ` [PATCH][v2] " Martin Liška
2017-08-10 13:49               ` Jan Hubicka
2023-09-08 12:02                 ` More '#ifdef ASM_OUTPUT_DEF' -> 'if (TARGET_SUPPORTS_ALIASES)' etc. (was: [PATCH][v2] Introduce TARGET_SUPPORTS_ALIASES) Thomas Schwinge
2023-09-19  8:47                   ` [PING] " Thomas Schwinge
2023-10-25  8:38                     ` [PING^2] " Thomas Schwinge
2023-10-25 16:19                       ` [PING^2] More '#ifdef ASM_OUTPUT_DEF' -> 'if (TARGET_SUPPORTS_ALIASES)' etc Jeff Law
2017-07-25  4:20       ` [PATCH] Fix wrong condition in ipa-visibility.c (PR ipa/81520) Yuri Gribov
2017-08-02  9:47     ` [PATCHv2][PING^2][PR 56727] Bypass PLT for recursive calls Jan Hubicka

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=CAJOtW+7RqLrkyNywgZFZ2GbintGAz6bitoAoCDYiiiiEt602_g@mail.gmail.com \
    --to=tetra2005@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hubicka@ucw.cz \
    /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).