[rs6000] Do not generate sibling call to nested function

Message ID 2045800.G86V45WoCa@polaris
State New
Headers show
Series
  • [rs6000] Do not generate sibling call to nested function
Related show

Commit Message

Eric Botcazou Sept. 17, 2018, 9:11 a.m.
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

Comments

Segher Boessenkool Sept. 18, 2018, 2:56 p.m. | #1
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
Kyrill Tkachov Sept. 24, 2018, 12:25 p.m. | #2
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
Eric Botcazou Sept. 25, 2018, 9:48 a.m. | #3
> 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

Patch

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