public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Kewen.Lin" <linkw@linux.ibm.com>
To: Ajit Agarwal <aagarwa1@linux.ibm.com>,
	Peter Bergner <bergner@linux.ibm.com>
Cc: Jakub Jelinek <jakub@redhat.com>,
	Segher Boessenkool <segher@kernel.crashing.org>,
	David Edelsohn <dje.gcc@gmail.com>,
	Michael Meissner <meissner@linux.ibm.com>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH v2] rs6000: Stackoverflow in optimized code on PPC [PR100799]
Date: Tue, 2 Apr 2024 14:12:04 +0800	[thread overview]
Message-ID: <d007c7d6-73e5-4961-aa46-590f4800977a@linux.ibm.com> (raw)
In-Reply-To: <5a2e511a-3a29-4cdd-88b1-12a6274d5a79@linux.ibm.com>

Hi!

on 2024/3/24 02:37, Ajit Agarwal wrote:
> 
> 
> On 23/03/24 9:33 pm, Peter Bergner wrote:
>> On 3/23/24 4:33 AM, Ajit Agarwal wrote:
>>>>> -      else if (align_words < GP_ARG_NUM_REG)
>>>>> +      else if (align_words < GP_ARG_NUM_REG
>>>>> +	       || (cum->hidden_string_length
>>>>> +	       && cum->actual_parm_length <= GP_ARG_NUM_REG))
>>>>         {
>>>>           if (TARGET_32BIT && TARGET_POWERPC64)
>>>>             return rs6000_mixed_function_arg (mode, type, align_words);
>>>>
>>>>           return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
>>>>         }
>>>>       else
>>>>         return NULL_RTX;
>>>>
>>>> The old code for the unused hidden parameter (which was the 9th param) would
>>>> fall thru to the "return NULL_RTX;" which would make the callee assume there
>>>> was a parameter save area allocated.  Now instead, we'll return a reg rtx,
>>>> probably of r11 (r3 thru r10 are our param regs) and I'm guessing we'll now
>>>> see a copy of r11 into a pseudo like we do for the other param regs.
>>>> Is that a problem? Given it's an unused parameter, it'll probably get deleted
>>>> as dead code, but could it cause any issues?  What if we have more than one

I think Peter raised one good point, not sure it would really cause some issues,
but the assigned reg goes beyond GP_ARG_MAX_REG, at least it is confusing to people
especially without DCE like at -O0.  Can we aggressively remove these candidates
from DECL_ARGUMENTS chain?  Does it cause any assertion to fail?

BR,
Kewen


>>>> unused hidden parameter and we return r12 and r13 which have specific uses
>>>> in our ABIs (eg, r13 is our TCB pointer), so it may not actually look dead.
>>>> Have you verified what the callee RTL looks like after expand for these
>>>> unused hidden parameters?  Is there a rtx we can return that isn't a NULL_RTX
>>>> which triggers the assumption of a parameter save area, but isn't a reg rtx
>>>> which might lead to some rtl being generated?  Would a (const_int 0) or
>>>> something else work?
>>>>
>>>>
>>> For the above use case it will return 
>>>
>>> (reg:DI 5 %r5) and below check entry_parm = 
>>> (reg:DI 5 %r5) and the following check will not return TRUE and hence
>>>                parameter save area will not be allocated.
>>
>> Why r5?!?!   The 8th (integer) param would return r10, so I'd assume if
>> the next param was a hidden param, then it'd get the next gpr, so r11.
>> How does it jump back to r5 which may have been used by the 3rd param?
>>
>>
> My mistake its r11 only for hidden param.
>>
>>
>>
>>> It will not generate any rtx in the callee rtl code but it just used to
>>> check whether to allocate parameter save area or not when number of args > 8.
>>>
>>> /* If there is no incoming register, we need a stack.  */
>>>   entry_parm = rs6000_function_arg (args_so_far, arg);
>>>   if (entry_parm == NULL)
>>>     return true;
>>>
>>>   /* Likewise if we need to pass both in registers and on the stack.  */
>>>   if (GET_CODE (entry_parm) == PARALLEL
>>>       && XEXP (XVECEXP (entry_parm, 0, 0), 0) == NULL_RTX)
>>>     return true;
>>
>> Yes, this code in rs6000_parm_needs_stack() uses the rs6000_function_arg()
>> return value as a boolean to tell us whether a parameter save area is required
>> so what we return is unimportant other than to know it's not NULL_RTX.
>>
>> I'm more concerned about the use of the target hook targetm.calls.function_arg
>> used in the generic parts of the compiler.  What will that code do differently
>> now that we return a reg rtx rather than NULL_RTX?  Might that code use
>> the reg rtx to emit something?  I'd feel better if you could verify what
>> happens in that code when we return a reg rtx for that 9th hidden param which
>> isn't really being passed in a register.
>>
> 
> As per my understanding and debugging openBLAS code testcase I see that reg_rtx returned inside the below IF condition is used for check whether paramter save area is needed or not. 
> 
> In the generic code where targetm.calls.function_arg is called 
> in calls.cc returned rtx is used for PARALLEL case so that we can
> check if we need to pass both in registers and stack then they emit
> store with respect to return rtx. If we identify that we need only
> registers for argument then it emits nothing.
> 
> Thanks & Regards
> Ajit
>>
>> Peter
>>
>>


  reply	other threads:[~2024-04-02  6:12 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-22 10:15 Ajit Agarwal
2024-03-23  4:37 ` Peter Bergner
2024-03-23  9:33   ` Ajit Agarwal
2024-03-23 14:28     ` Ajit Agarwal
2024-03-23 16:03     ` Peter Bergner
2024-03-23 18:37       ` Ajit Agarwal
2024-04-02  6:12         ` Kewen.Lin [this message]
2024-04-02  8:03           ` Jakub Jelinek
2024-04-03  5:18             ` Kewen.Lin
2024-04-03  8:35               ` Jakub Jelinek
2024-04-03  9:02                 ` Kewen.Lin
2024-04-03  9:23                   ` Jakub Jelinek
2024-04-03 11:01                     ` Kewen.Lin
2024-04-03 11:18                       ` Jakub Jelinek
2024-04-03 12:18                         ` Kewen.Lin

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=d007c7d6-73e5-4961-aa46-590f4800977a@linux.ibm.com \
    --to=linkw@linux.ibm.com \
    --cc=aagarwa1@linux.ibm.com \
    --cc=bergner@linux.ibm.com \
    --cc=dje.gcc@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=meissner@linux.ibm.com \
    --cc=segher@kernel.crashing.org \
    /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).