public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [rs6000] Do not generate sibling call to nested function
@ 2018-09-17  9:14 Eric Botcazou
  2018-09-18 15:26 ` Segher Boessenkool
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Botcazou @ 2018-09-17  9:14 UTC (permalink / raw)
  To: gcc-patches

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

Hi,

more precisely, to a nested function that requires a static chain.  The reason 
is that the sibling call epilogue may clobber the static chain register r11.

Tested on PowerPC/Linux, OK for the mainline?


2018-09-17  Eric Botcazou  <ebotcazou@adacore.com>

	* config/rs6000/rs6000.c (rs6000_function_ok_for_sibcall): Return false
	if the call takes a static chain.


2018-09-17  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc.dg/nested-func-11.c: New test.

-- 
Eric Botcazou

[-- Attachment #2: nested-func-11.c --]
[-- Type: text/x-csrc, Size: 443 bytes --]

/* { dg-do run } */
/* { dg-options "-O2 -fno-omit-frame-pointer" } */

int __attribute__((noipa)) foo (int i)
{
  int a;

  void __attribute__((noipa)) nested2 (int i)
  {
    a = i;
  }

  void  __attribute__((noipa)) nested1 (int i)
  {
    int b[32];

    for (int j = 0; j < 32; j++)
      b[j] = i + j;

    nested2 (b[i]);
  }

  nested1 (i);

  return a;
}

int main (void)
{
  if (foo (4) != 8)
    __builtin_abort ();

  return 0;
}

[-- Attachment #3: p.diff --]
[-- Type: text/x-patch, Size: 453 bytes --]

Index: config/rs6000/rs6000.c
===================================================================
--- config/rs6000/rs6000.c	(revision 264342)
+++ config/rs6000/rs6000.c	(working copy)
@@ -24332,6 +24332,10 @@ rs6000_function_ok_for_sibcall (tree dec
 {
   tree fntype;
 
+  /* The sibcall epilogue may clobber the static chain register.  */
+  if (CALL_EXPR_STATIC_CHAIN (exp))
+    return false;
+
   if (decl)
     fntype = TREE_TYPE (decl);
   else

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [rs6000] Do not generate sibling call to nested function
  2018-09-17  9:14 [rs6000] Do not generate sibling call to nested function Eric Botcazou
@ 2018-09-18 15:26 ` Segher Boessenkool
  2018-09-24 13:20   ` Kyrill Tkachov
  0 siblings, 1 reply; 4+ messages in thread
From: Segher Boessenkool @ 2018-09-18 15:26 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: gcc-patches

Hi!

On Mon, Sep 17, 2018 at 11:11:53AM +0200, Eric Botcazou wrote:
> more precisely, to a nested function that requires a static chain.  The reason 
> is that the sibling call epilogue may clobber the static chain register r11.
> 
> Tested on PowerPC/Linux, OK for the mainline?
> 
> 
> 2018-09-17  Eric Botcazou  <ebotcazou@adacore.com>
> 
> 	* config/rs6000/rs6000.c (rs6000_function_ok_for_sibcall): Return false
> 	if the call takes a static chain.


> --- config/rs6000/rs6000.c	(revision 264342)
> +++ config/rs6000/rs6000.c	(working copy)
> @@ -24332,6 +24332,10 @@ rs6000_function_ok_for_sibcall (tree dec
>  {
>    tree fntype;
>  
> +  /* The sibcall epilogue may clobber the static chain register.  */
> +  if (CALL_EXPR_STATIC_CHAIN (exp))
> +    return false;
> +
>    if (decl)
>      fntype = TREE_TYPE (decl);
>    else

We could probably make sibcalls work with static chain, but that is most
likely not worth it.  Could you change the comment to say something like
that?

Approved for trunk and backports.  Thanks!


Segher

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [rs6000] Do not generate sibling call to nested function
  2018-09-18 15:26 ` Segher Boessenkool
@ 2018-09-24 13:20   ` Kyrill Tkachov
  2018-09-25 10:10     ` Eric Botcazou
  0 siblings, 1 reply; 4+ messages in thread
From: Kyrill Tkachov @ 2018-09-24 13:20 UTC (permalink / raw)
  To: Segher Boessenkool, Eric Botcazou; +Cc: gcc-patches

Hi Eric,

On 18/09/18 15:56, Segher Boessenkool wrote:
> Hi!
>
> On Mon, Sep 17, 2018 at 11:11:53AM +0200, Eric Botcazou wrote:
> > more precisely, to a nested function that requires a static chain.  The reason
> > is that the sibling call epilogue may clobber the static chain register r11.
> >
> > Tested on PowerPC/Linux, OK for the mainline?
> >
> >
> > 2018-09-17  Eric Botcazou <ebotcazou@adacore.com>
> >
> >        * config/rs6000/rs6000.c (rs6000_function_ok_for_sibcall): Return false
> >        if the call takes a static chain.
>
>
> > --- config/rs6000/rs6000.c    (revision 264342)
> > +++ config/rs6000/rs6000.c    (working copy)
> > @@ -24332,6 +24332,10 @@ rs6000_function_ok_for_sibcall (tree dec
> >  {
> >    tree fntype;
> >
> > +  /* The sibcall epilogue may clobber the static chain register.  */
> > +  if (CALL_EXPR_STATIC_CHAIN (exp))
> > +    return false;
> > +
> >    if (decl)
> >      fntype = TREE_TYPE (decl);
> >    else
>
> We could probably make sibcalls work with static chain, but that is most
> likely not worth it.  Could you change the comment to say something like
> that?
>
> Approved for trunk and backports.  Thanks!
>

I'm seeing a testism on the GCC 7 branch due to the noipa attribute in the testcase.
I think it doesn't exist in GCC 7 so we're getting a test for excess errors FAIL:

warning: 'noipa' attribute directive ignored [-Wattributes]

Any chance we can adjust the testcase?

Thanks,
Kyrill

>
> Segher

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [rs6000] Do not generate sibling call to nested function
  2018-09-24 13:20   ` Kyrill Tkachov
@ 2018-09-25 10:10     ` Eric Botcazou
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Botcazou @ 2018-09-25 10:10 UTC (permalink / raw)
  To: Kyrill Tkachov; +Cc: gcc-patches, Segher Boessenkool

> I'm seeing a testism on the GCC 7 branch due to the noipa attribute in the
> testcase. I think it doesn't exist in GCC 7 so we're getting a test for
> excess errors FAIL:
> 
> warning: 'noipa' attribute directive ignored [-Wattributes]
> 
> Any chance we can adjust the testcase?

Yes, I did it yesterday.

-- 
Eric Botcazou

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-09-25  9:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-17  9:14 [rs6000] Do not generate sibling call to nested function Eric Botcazou
2018-09-18 15:26 ` Segher Boessenkool
2018-09-24 13:20   ` Kyrill Tkachov
2018-09-25 10:10     ` Eric Botcazou

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