public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, rs6000] Fix alias set of link reg save MEM
@ 2021-06-01 20:34 Pat Haugen
  2021-06-01 21:36 ` Segher Boessenkool
  2021-06-02  6:51 ` Richard Biener
  0 siblings, 2 replies; 8+ messages in thread
From: Pat Haugen @ 2021-06-01 20:34 UTC (permalink / raw)
  To: GCC Patches; +Cc: Segher Boessenkool

Make sure link reg save MEM has frame alias set, to match other link reg
save/restore code.

Bootstrap/regtest on powerpc64/powerpc64le with no new regressions. Ok for
trunk?

-Pat


2021-06-01  Pat Haugen  <pthaugen@linux.ibm.com>

gcc/ChangeLog:

	* config/rs6000/rs6000-logue.c (rs6000_emit_prologue): Use
	gen_frame_store.



diff --git a/gcc/config/rs6000/rs6000-logue.c b/gcc/config/rs6000/rs6000-logue.c
index 13c00e740d6..07337c4836a 100644
--- a/gcc/config/rs6000/rs6000-logue.c
+++ b/gcc/config/rs6000/rs6000-logue.c
@@ -3257,7 +3257,7 @@ rs6000_emit_prologue (void)
   if (!WORLD_SAVE_P (info) && info->lr_save_p
       && !cfun->machine->lr_is_wrapped_separately)
     {
-      rtx addr, reg, mem;
+      rtx reg;
 
       reg = gen_rtx_REG (Pmode, 0);
       START_USE (0);
@@ -3267,13 +3267,8 @@ rs6000_emit_prologue (void)
       if (!(strategy & (SAVE_NOINLINE_GPRS_SAVES_LR
 			| SAVE_NOINLINE_FPRS_SAVES_LR)))
 	{
-	  addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
-			       GEN_INT (info->lr_save_offset + frame_off));
-	  mem = gen_rtx_MEM (Pmode, addr);
-	  /* This should not be of rs6000_sr_alias_set, because of
-	     __builtin_return_address.  */
-
-	  insn = emit_move_insn (mem, reg);
+	  insn = emit_insn (gen_frame_store (reg, frame_reg_rtx,
+					     info->lr_save_offset + frame_off));
 	  rs6000_frame_related (insn, frame_reg_rtx, sp_off - frame_off,
 				NULL_RTX, NULL_RTX);
 	  END_USE (0);

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

* Re: [PATCH, rs6000] Fix alias set of link reg save MEM
  2021-06-01 20:34 [PATCH, rs6000] Fix alias set of link reg save MEM Pat Haugen
@ 2021-06-01 21:36 ` Segher Boessenkool
  2021-06-02  6:51 ` Richard Biener
  1 sibling, 0 replies; 8+ messages in thread
From: Segher Boessenkool @ 2021-06-01 21:36 UTC (permalink / raw)
  To: Pat Haugen; +Cc: GCC Patches

On Tue, Jun 01, 2021 at 03:34:50PM -0500, Pat Haugen wrote:
> Make sure link reg save MEM has frame alias set, to match other link reg
> save/restore code.

Okay for trunk and any backports (please do at least GCC 11).  Thanks!


Segher

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

* Re: [PATCH, rs6000] Fix alias set of link reg save MEM
  2021-06-01 20:34 [PATCH, rs6000] Fix alias set of link reg save MEM Pat Haugen
  2021-06-01 21:36 ` Segher Boessenkool
@ 2021-06-02  6:51 ` Richard Biener
  2021-06-02 11:15   ` Pat Haugen
  1 sibling, 1 reply; 8+ messages in thread
From: Richard Biener @ 2021-06-02  6:51 UTC (permalink / raw)
  To: Pat Haugen; +Cc: GCC Patches, Segher Boessenkool

On Tue, Jun 1, 2021 at 10:37 PM Pat Haugen via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Make sure link reg save MEM has frame alias set, to match other link reg
> save/restore code.
>
> Bootstrap/regtest on powerpc64/powerpc64le with no new regressions. Ok for
> trunk?
>
> -Pat
>
>
> 2021-06-01  Pat Haugen  <pthaugen@linux.ibm.com>
>
> gcc/ChangeLog:
>
>         * config/rs6000/rs6000-logue.c (rs6000_emit_prologue): Use
>         gen_frame_store.
>
>
>
> diff --git a/gcc/config/rs6000/rs6000-logue.c b/gcc/config/rs6000/rs6000-logue.c
> index 13c00e740d6..07337c4836a 100644
> --- a/gcc/config/rs6000/rs6000-logue.c
> +++ b/gcc/config/rs6000/rs6000-logue.c
> @@ -3257,7 +3257,7 @@ rs6000_emit_prologue (void)
>    if (!WORLD_SAVE_P (info) && info->lr_save_p
>        && !cfun->machine->lr_is_wrapped_separately)
>      {
> -      rtx addr, reg, mem;
> +      rtx reg;
>
>        reg = gen_rtx_REG (Pmode, 0);
>        START_USE (0);
> @@ -3267,13 +3267,8 @@ rs6000_emit_prologue (void)
>        if (!(strategy & (SAVE_NOINLINE_GPRS_SAVES_LR
>                         | SAVE_NOINLINE_FPRS_SAVES_LR)))
>         {
> -         addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
> -                              GEN_INT (info->lr_save_offset + frame_off));
> -         mem = gen_rtx_MEM (Pmode, addr);
> -         /* This should not be of rs6000_sr_alias_set, because of
> -            __builtin_return_address.  */

I can't figure what this comment meant - did you?  Note the old code
looks like it would end up with alias-set zero and thus more conservative
than with using frame-alias-set so this is an optimization?

Thanks,
Richard.

> -         insn = emit_move_insn (mem, reg);
> +         insn = emit_insn (gen_frame_store (reg, frame_reg_rtx,
> +                                            info->lr_save_offset + frame_off));
>           rs6000_frame_related (insn, frame_reg_rtx, sp_off - frame_off,
>                                 NULL_RTX, NULL_RTX);
>           END_USE (0);

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

* Re: [PATCH, rs6000] Fix alias set of link reg save MEM
  2021-06-02  6:51 ` Richard Biener
@ 2021-06-02 11:15   ` Pat Haugen
  2021-06-02 12:01     ` Richard Biener
  0 siblings, 1 reply; 8+ messages in thread
From: Pat Haugen @ 2021-06-02 11:15 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches, Segher Boessenkool

On 6/2/21 1:51 AM, Richard Biener wrote:
> On Tue, Jun 1, 2021 at 10:37 PM Pat Haugen via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
>>
>> Make sure link reg save MEM has frame alias set, to match other link reg
>> save/restore code.
>>
>> Bootstrap/regtest on powerpc64/powerpc64le with no new regressions. Ok for
>> trunk?
>>
>> -Pat
>>
>>
>> 2021-06-01  Pat Haugen  <pthaugen@linux.ibm.com>
>>
>> gcc/ChangeLog:
>>
>>         * config/rs6000/rs6000-logue.c (rs6000_emit_prologue): Use
>>         gen_frame_store.
>>
>>
>>
>> diff --git a/gcc/config/rs6000/rs6000-logue.c b/gcc/config/rs6000/rs6000-logue.c
>> index 13c00e740d6..07337c4836a 100644
>> --- a/gcc/config/rs6000/rs6000-logue.c
>> +++ b/gcc/config/rs6000/rs6000-logue.c
>> @@ -3257,7 +3257,7 @@ rs6000_emit_prologue (void)
>>    if (!WORLD_SAVE_P (info) && info->lr_save_p
>>        && !cfun->machine->lr_is_wrapped_separately)
>>      {
>> -      rtx addr, reg, mem;
>> +      rtx reg;
>>
>>        reg = gen_rtx_REG (Pmode, 0);
>>        START_USE (0);
>> @@ -3267,13 +3267,8 @@ rs6000_emit_prologue (void)
>>        if (!(strategy & (SAVE_NOINLINE_GPRS_SAVES_LR
>>                         | SAVE_NOINLINE_FPRS_SAVES_LR)))
>>         {
>> -         addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
>> -                              GEN_INT (info->lr_save_offset + frame_off));
>> -         mem = gen_rtx_MEM (Pmode, addr);
>> -         /* This should not be of rs6000_sr_alias_set, because of
>> -            __builtin_return_address.  */
> 
> I can't figure what this comment meant - did you?  Note the old code
> looks like it would end up with alias-set zero and thus more conservative
> than with using frame-alias-set so this is an optimization?

No, I couldn't figure out the reasoning for the comment/code either. It's been that way since it was introduced in March 2000 as part of the “Merge in changes from newppc-branch.” patch. All other places where we save/restore the link reg use a MEM with frame-alias-set. This change is an optimization as you suspect in that it allows us to schedule non-aliased loads above the link reg store (which couldn't happen before due to use of alias-set zero).

-Pat

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

* Re: [PATCH, rs6000] Fix alias set of link reg save MEM
  2021-06-02 11:15   ` Pat Haugen
@ 2021-06-02 12:01     ` Richard Biener
  2021-06-02 13:23       ` Pat Haugen
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Biener @ 2021-06-02 12:01 UTC (permalink / raw)
  To: Pat Haugen; +Cc: GCC Patches, Segher Boessenkool

On Wed, Jun 2, 2021 at 1:15 PM Pat Haugen <pthaugen@linux.ibm.com> wrote:
>
> On 6/2/21 1:51 AM, Richard Biener wrote:
> > On Tue, Jun 1, 2021 at 10:37 PM Pat Haugen via Gcc-patches
> > <gcc-patches@gcc.gnu.org> wrote:
> >>
> >> Make sure link reg save MEM has frame alias set, to match other link reg
> >> save/restore code.
> >>
> >> Bootstrap/regtest on powerpc64/powerpc64le with no new regressions. Ok for
> >> trunk?
> >>
> >> -Pat
> >>
> >>
> >> 2021-06-01  Pat Haugen  <pthaugen@linux.ibm.com>
> >>
> >> gcc/ChangeLog:
> >>
> >>         * config/rs6000/rs6000-logue.c (rs6000_emit_prologue): Use
> >>         gen_frame_store.
> >>
> >>
> >>
> >> diff --git a/gcc/config/rs6000/rs6000-logue.c b/gcc/config/rs6000/rs6000-logue.c
> >> index 13c00e740d6..07337c4836a 100644
> >> --- a/gcc/config/rs6000/rs6000-logue.c
> >> +++ b/gcc/config/rs6000/rs6000-logue.c
> >> @@ -3257,7 +3257,7 @@ rs6000_emit_prologue (void)
> >>    if (!WORLD_SAVE_P (info) && info->lr_save_p
> >>        && !cfun->machine->lr_is_wrapped_separately)
> >>      {
> >> -      rtx addr, reg, mem;
> >> +      rtx reg;
> >>
> >>        reg = gen_rtx_REG (Pmode, 0);
> >>        START_USE (0);
> >> @@ -3267,13 +3267,8 @@ rs6000_emit_prologue (void)
> >>        if (!(strategy & (SAVE_NOINLINE_GPRS_SAVES_LR
> >>                         | SAVE_NOINLINE_FPRS_SAVES_LR)))
> >>         {
> >> -         addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
> >> -                              GEN_INT (info->lr_save_offset + frame_off));
> >> -         mem = gen_rtx_MEM (Pmode, addr);
> >> -         /* This should not be of rs6000_sr_alias_set, because of
> >> -            __builtin_return_address.  */
> >
> > I can't figure what this comment meant - did you?  Note the old code
> > looks like it would end up with alias-set zero and thus more conservative
> > than with using frame-alias-set so this is an optimization?
>
> No, I couldn't figure out the reasoning for the comment/code either. It's been that way since it was introduced in March 2000 as part of the “Merge in changes from newppc-branch.” patch. All other places where we save/restore the link reg use a MEM with frame-alias-set. This change is an optimization as you suspect in that it allows us to schedule non-aliased loads above the link reg store (which couldn't happen before due to use of alias-set zero).

So did you check the RTL (and alias-sets) produced by
__builtin_return_address?  Test coverage might
be low here and w/o scheduling opportunities to break things.

Richard.

> -Pat

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

* Re: [PATCH, rs6000] Fix alias set of link reg save MEM
  2021-06-02 12:01     ` Richard Biener
@ 2021-06-02 13:23       ` Pat Haugen
  2021-06-02 14:19         ` Segher Boessenkool
  0 siblings, 1 reply; 8+ messages in thread
From: Pat Haugen @ 2021-06-02 13:23 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches, Segher Boessenkool

On 6/2/21 7:01 AM, Richard Biener wrote:
> On Wed, Jun 2, 2021 at 1:15 PM Pat Haugen <pthaugen@linux.ibm.com> wrote:
>>
>> On 6/2/21 1:51 AM, Richard Biener wrote:
>>> On Tue, Jun 1, 2021 at 10:37 PM Pat Haugen via Gcc-patches
>>> <gcc-patches@gcc.gnu.org> wrote:
>>>>
>>>> Make sure link reg save MEM has frame alias set, to match other link reg
>>>> save/restore code.
>>>>
>>>> Bootstrap/regtest on powerpc64/powerpc64le with no new regressions. Ok for
>>>> trunk?
>>>>
>>>> -Pat
>>>>
>>>>
>>>> 2021-06-01  Pat Haugen  <pthaugen@linux.ibm.com>
>>>>
>>>> gcc/ChangeLog:
>>>>
>>>>         * config/rs6000/rs6000-logue.c (rs6000_emit_prologue): Use
>>>>         gen_frame_store.
>>>>
>>>>
>>>>
>>>> diff --git a/gcc/config/rs6000/rs6000-logue.c b/gcc/config/rs6000/rs6000-logue.c
>>>> index 13c00e740d6..07337c4836a 100644
>>>> --- a/gcc/config/rs6000/rs6000-logue.c
>>>> +++ b/gcc/config/rs6000/rs6000-logue.c
>>>> @@ -3257,7 +3257,7 @@ rs6000_emit_prologue (void)
>>>>    if (!WORLD_SAVE_P (info) && info->lr_save_p
>>>>        && !cfun->machine->lr_is_wrapped_separately)
>>>>      {
>>>> -      rtx addr, reg, mem;
>>>> +      rtx reg;
>>>>
>>>>        reg = gen_rtx_REG (Pmode, 0);
>>>>        START_USE (0);
>>>> @@ -3267,13 +3267,8 @@ rs6000_emit_prologue (void)
>>>>        if (!(strategy & (SAVE_NOINLINE_GPRS_SAVES_LR
>>>>                         | SAVE_NOINLINE_FPRS_SAVES_LR)))
>>>>         {
>>>> -         addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
>>>> -                              GEN_INT (info->lr_save_offset + frame_off));
>>>> -         mem = gen_rtx_MEM (Pmode, addr);
>>>> -         /* This should not be of rs6000_sr_alias_set, because of
>>>> -            __builtin_return_address.  */
>>>
>>> I can't figure what this comment meant - did you?  Note the old code
>>> looks like it would end up with alias-set zero and thus more conservative
>>> than with using frame-alias-set so this is an optimization?
>>
>> No, I couldn't figure out the reasoning for the comment/code either. It's been that way since it was introduced in March 2000 as part of the “Merge in changes from newppc-branch.” patch. All other places where we save/restore the link reg use a MEM with frame-alias-set. This change is an optimization as you suspect in that it allows us to schedule non-aliased loads above the link reg store (which couldn't happen before due to use of alias-set zero).
> 
> So did you check the RTL (and alias-sets) produced by
> __builtin_return_address?  Test coverage might
> be low here and w/o scheduling opportunities to break things.

__builtin_return_address creates it's own copy of the link reg to a pseudo upon function entry. It doesn't appear to try and "reuse" any LR copy/save location that might be generated via the prolog code. References to __builtin_return_address will then refer to that pseudo. So I don't see any connection between the prolog save code and __builtin_return_address.

-Pat

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

* Re: [PATCH, rs6000] Fix alias set of link reg save MEM
  2021-06-02 13:23       ` Pat Haugen
@ 2021-06-02 14:19         ` Segher Boessenkool
  2021-06-02 15:01           ` Pat Haugen
  0 siblings, 1 reply; 8+ messages in thread
From: Segher Boessenkool @ 2021-06-02 14:19 UTC (permalink / raw)
  To: Pat Haugen; +Cc: Richard Biener, GCC Patches

On Wed, Jun 02, 2021 at 08:23:48AM -0500, Pat Haugen wrote:
> On 6/2/21 7:01 AM, Richard Biener wrote:
> > So did you check the RTL (and alias-sets) produced by
> > __builtin_return_address?  Test coverage might
> > be low here and w/o scheduling opportunities to break things.
> 
> __builtin_return_address creates it's own copy of the link reg to a pseudo upon function entry. It doesn't appear to try and "reuse" any LR copy/save location that might be generated via the prolog code. References to __builtin_return_address will then refer to that pseudo. So I don't see any connection between the prolog save code and __builtin_return_address.

That is for __builtin_return_address(0), the simple (and always working)
one.  It is harder for non-zero arguments (although I don't see why
those would not work, even with inlining).


Segher

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

* Re: [PATCH, rs6000] Fix alias set of link reg save MEM
  2021-06-02 14:19         ` Segher Boessenkool
@ 2021-06-02 15:01           ` Pat Haugen
  0 siblings, 0 replies; 8+ messages in thread
From: Pat Haugen @ 2021-06-02 15:01 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: Richard Biener, GCC Patches

On 6/2/21 9:19 AM, Segher Boessenkool wrote:
> On Wed, Jun 02, 2021 at 08:23:48AM -0500, Pat Haugen wrote:
>> On 6/2/21 7:01 AM, Richard Biener wrote:
>>> So did you check the RTL (and alias-sets) produced by
>>> __builtin_return_address?  Test coverage might
>>> be low here and w/o scheduling opportunities to break things.
>>
>> __builtin_return_address creates it's own copy of the link reg to a pseudo upon function entry. It doesn't appear to try and "reuse" any LR copy/save location that might be generated via the prolog code. References to __builtin_return_address will then refer to that pseudo. So I don't see any connection between the prolog save code and __builtin_return_address.
> 
> That is for __builtin_return_address(0), the simple (and always working)
> one.  It is harder for non-zero arguments (although I don't see why
> those would not work, even with inlining).


Right, I realized after I sent the reply I was being a little too specific to __builtin_return_address(0). For non-zero args __builtin_return_address generates code to walk the appropriate number of stack frames back before loading the LR from the designated save area. All those mem references are using either frame-alias-set or 0 as their alias set, so we still should be fine. So regardless of the argument to the builtin, there is no connection between the current function's prologue LR save code and the code __builtin_return_address() would generate in the function.

-Pat

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

end of thread, other threads:[~2021-06-02 15:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-01 20:34 [PATCH, rs6000] Fix alias set of link reg save MEM Pat Haugen
2021-06-01 21:36 ` Segher Boessenkool
2021-06-02  6:51 ` Richard Biener
2021-06-02 11:15   ` Pat Haugen
2021-06-02 12:01     ` Richard Biener
2021-06-02 13:23       ` Pat Haugen
2021-06-02 14:19         ` Segher Boessenkool
2021-06-02 15:01           ` Pat Haugen

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