Re: V3: [PATCH] Update preferred_stack_boundary only when expanding function call

2019-06-14 Thread Richard Sandiford
"H.J. Lu"  writes:
> On Fri, Jun 14, 2019 at 8:31 AM Richard Sandiford
>  wrote:
>>
>> "H.J. Lu"  writes:
>> > diff --git a/gcc/calls.c b/gcc/calls.c
>> > index c8a42680041..6ab138e7bb0 100644
>> > --- a/gcc/calls.c
>> > +++ b/gcc/calls.c
>> > @@ -3226,6 +3226,19 @@ can_implement_as_sibling_call_p (tree exp,
>> >return true;
>> >  }
>> >
>> > +/* Update stack alignment when the parameter is passed in the stack
>> > +   since the outgoing parameter requires extra alignment on the calling
>> > +   function side. */
>> > +
>> > +static void
>> > +update_stack_alignment_for_call (struct locate_and_pad_arg_data *locate)
>> > +{
>> > +  if (crtl->stack_alignment_needed < locate->boundary)
>> > +crtl->stack_alignment_needed = locate->boundary;
>> > +  if (crtl->preferred_stack_boundary < locate->boundary)
>> > +crtl->preferred_stack_boundary = locate->boundary;
>> > +}
>> > +
>> >  /* Generate all the code for a CALL_EXPR exp
>> > and return an rtx for its value.
>> > Store the value in TARGET (specified as an rtx) if convenient.
>> > @@ -3703,6 +3716,12 @@ expand_call (tree exp, rtx target, int ignore)
>> >/* Ensure current function's preferred stack boundary is at least
>> >   what we need.  Stack alignment may also increase preferred stack
>> >   boundary.  */
>> > +  for (i = 0; i < num_actuals; i++)
>> > +if (reg_parm_stack_space > 0
>> > + || args[i].reg == 0
>> > + || args[i].partial != 0
>> > + || args[i].pass_on_stack)
>> > +  update_stack_alignment_for_call ([i].locate);
>> >if (crtl->preferred_stack_boundary < preferred_stack_boundary)
>> >  crtl->preferred_stack_boundary = preferred_stack_boundary;
>> >else
>> > @@ -4961,6 +4980,12 @@ emit_library_call_value_1 (int retval, rtx orgfun, 
>> > rtx value,
>> >targetm.calls.function_arg_advance (args_so_far, mode, (tree) 0, 
>> > true);
>> >  }
>> >
>> > +  for (int i = 0; i < nargs; i++)
>> > +if (reg_parm_stack_space > 0
>> > + || argvec[i].reg == 0
>> > + || argvec[i].partial != 0)
>> > +  update_stack_alignment_for_call ([i].locate);
>> > +
>>
>> It's safe to test argvec[i].pass_on_stack here too, since the vector
>
> There is no pass_on_stack in argvec:
>
>   struct arg
>   {
> rtx value;
> machine_mode mode;
> rtx reg;
> int partial;
> struct locate_and_pad_arg_data locate;
> rtx save_area;
>   };
>   struct arg *argvec;
>
>> is initialised to zeros.  So I think we should move the "if"s into the
>> new function:
>>
>> static void
>> update_stack_alignment_for_call (struct locate_and_pad_arg_data *locate)
>> {
>>   if (reg_parm_stack_space > 0
>>   || locate->reg == 0
>>   || locate->partial != 0
>>   || locate->pass_on_stack)
>
> Since we have
>
> struct locate_and_pad_arg_data
> {
>   /* Size of this argument on the stack, rounded up for any padding it
>  gets.  If REG_PARM_STACK_SPACE is defined, then register parms are
>  counted here, otherwise they aren't.  */
>   struct args_size size;
>   /* Offset of this argument from beginning of stack-args.  */
>   struct args_size offset;
>   /* Offset to the start of the stack slot.  Different from OFFSET
>  if this arg pads downward.  */
>   struct args_size slot_offset;
>   /* The amount that the stack pointer needs to be adjusted to
>  force alignment for the next argument.  */
>   struct args_size alignment_pad;
>   /* Which way we should pad this arg.  */
>   pad_direction where_pad;
>   /* slot_offset is at least this aligned.  */
>   unsigned int boundary;
> };
>
> we can't check reg, partial nor pass_on_stack here.

Sorry, missed that they were different structures.

>> {
>>   if (crtl->stack_alignment_needed < locate->boundary)
>> crtl->stack_alignment_needed = locate->boundary;
>>   if (crtl->preferred_stack_boundary < locate->boundary)
>> crtl->preferred_stack_boundary = locate->boundary;
>> }
>> }
>>
>> OK with that change, thanks.
>>
>
> Is my original patch OK?

Yes, thanks.

Richard


Re: V3: [PATCH] Update preferred_stack_boundary only when expanding function call

2019-06-14 Thread H.J. Lu
On Fri, Jun 14, 2019 at 8:31 AM Richard Sandiford
 wrote:
>
> "H.J. Lu"  writes:
> > diff --git a/gcc/calls.c b/gcc/calls.c
> > index c8a42680041..6ab138e7bb0 100644
> > --- a/gcc/calls.c
> > +++ b/gcc/calls.c
> > @@ -3226,6 +3226,19 @@ can_implement_as_sibling_call_p (tree exp,
> >return true;
> >  }
> >
> > +/* Update stack alignment when the parameter is passed in the stack
> > +   since the outgoing parameter requires extra alignment on the calling
> > +   function side. */
> > +
> > +static void
> > +update_stack_alignment_for_call (struct locate_and_pad_arg_data *locate)
> > +{
> > +  if (crtl->stack_alignment_needed < locate->boundary)
> > +crtl->stack_alignment_needed = locate->boundary;
> > +  if (crtl->preferred_stack_boundary < locate->boundary)
> > +crtl->preferred_stack_boundary = locate->boundary;
> > +}
> > +
> >  /* Generate all the code for a CALL_EXPR exp
> > and return an rtx for its value.
> > Store the value in TARGET (specified as an rtx) if convenient.
> > @@ -3703,6 +3716,12 @@ expand_call (tree exp, rtx target, int ignore)
> >/* Ensure current function's preferred stack boundary is at least
> >   what we need.  Stack alignment may also increase preferred stack
> >   boundary.  */
> > +  for (i = 0; i < num_actuals; i++)
> > +if (reg_parm_stack_space > 0
> > + || args[i].reg == 0
> > + || args[i].partial != 0
> > + || args[i].pass_on_stack)
> > +  update_stack_alignment_for_call ([i].locate);
> >if (crtl->preferred_stack_boundary < preferred_stack_boundary)
> >  crtl->preferred_stack_boundary = preferred_stack_boundary;
> >else
> > @@ -4961,6 +4980,12 @@ emit_library_call_value_1 (int retval, rtx orgfun, 
> > rtx value,
> >targetm.calls.function_arg_advance (args_so_far, mode, (tree) 0, 
> > true);
> >  }
> >
> > +  for (int i = 0; i < nargs; i++)
> > +if (reg_parm_stack_space > 0
> > + || argvec[i].reg == 0
> > + || argvec[i].partial != 0)
> > +  update_stack_alignment_for_call ([i].locate);
> > +
>
> It's safe to test argvec[i].pass_on_stack here too, since the vector

There is no pass_on_stack in argvec:

  struct arg
  {
rtx value;
machine_mode mode;
rtx reg;
int partial;
struct locate_and_pad_arg_data locate;
rtx save_area;
  };
  struct arg *argvec;

> is initialised to zeros.  So I think we should move the "if"s into the
> new function:
>
> static void
> update_stack_alignment_for_call (struct locate_and_pad_arg_data *locate)
> {
>   if (reg_parm_stack_space > 0
>   || locate->reg == 0
>   || locate->partial != 0
>   || locate->pass_on_stack)

Since we have

struct locate_and_pad_arg_data
{
  /* Size of this argument on the stack, rounded up for any padding it
 gets.  If REG_PARM_STACK_SPACE is defined, then register parms are
 counted here, otherwise they aren't.  */
  struct args_size size;
  /* Offset of this argument from beginning of stack-args.  */
  struct args_size offset;
  /* Offset to the start of the stack slot.  Different from OFFSET
 if this arg pads downward.  */
  struct args_size slot_offset;
  /* The amount that the stack pointer needs to be adjusted to
 force alignment for the next argument.  */
  struct args_size alignment_pad;
  /* Which way we should pad this arg.  */
  pad_direction where_pad;
  /* slot_offset is at least this aligned.  */
  unsigned int boundary;
};

we can't check reg, partial nor pass_on_stack here.

> {
>   if (crtl->stack_alignment_needed < locate->boundary)
> crtl->stack_alignment_needed = locate->boundary;
>   if (crtl->preferred_stack_boundary < locate->boundary)
> crtl->preferred_stack_boundary = locate->boundary;
> }
> }
>
> OK with that change, thanks.
>

Is my original patch OK?

Thanks.

-- 
H.J.


Re: V3: [PATCH] Update preferred_stack_boundary only when expanding function call

2019-06-14 Thread Richard Sandiford
"H.J. Lu"  writes:
> diff --git a/gcc/calls.c b/gcc/calls.c
> index c8a42680041..6ab138e7bb0 100644
> --- a/gcc/calls.c
> +++ b/gcc/calls.c
> @@ -3226,6 +3226,19 @@ can_implement_as_sibling_call_p (tree exp,
>return true;
>  }
>  
> +/* Update stack alignment when the parameter is passed in the stack
> +   since the outgoing parameter requires extra alignment on the calling
> +   function side. */
> +
> +static void
> +update_stack_alignment_for_call (struct locate_and_pad_arg_data *locate)
> +{
> +  if (crtl->stack_alignment_needed < locate->boundary)
> +crtl->stack_alignment_needed = locate->boundary;
> +  if (crtl->preferred_stack_boundary < locate->boundary)
> +crtl->preferred_stack_boundary = locate->boundary;
> +}
> +
>  /* Generate all the code for a CALL_EXPR exp
> and return an rtx for its value.
> Store the value in TARGET (specified as an rtx) if convenient.
> @@ -3703,6 +3716,12 @@ expand_call (tree exp, rtx target, int ignore)
>/* Ensure current function's preferred stack boundary is at least
>   what we need.  Stack alignment may also increase preferred stack
>   boundary.  */
> +  for (i = 0; i < num_actuals; i++)
> +if (reg_parm_stack_space > 0
> + || args[i].reg == 0
> + || args[i].partial != 0
> + || args[i].pass_on_stack)
> +  update_stack_alignment_for_call ([i].locate);
>if (crtl->preferred_stack_boundary < preferred_stack_boundary)
>  crtl->preferred_stack_boundary = preferred_stack_boundary;
>else
> @@ -4961,6 +4980,12 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx 
> value,
>targetm.calls.function_arg_advance (args_so_far, mode, (tree) 0, true);
>  }
>  
> +  for (int i = 0; i < nargs; i++)
> +if (reg_parm_stack_space > 0
> + || argvec[i].reg == 0
> + || argvec[i].partial != 0)
> +  update_stack_alignment_for_call ([i].locate);
> +

It's safe to test argvec[i].pass_on_stack here too, since the vector
is initialised to zeros.  So I think we should move the "if"s into the
new function:

static void
update_stack_alignment_for_call (struct locate_and_pad_arg_data *locate)
{
  if (reg_parm_stack_space > 0
  || locate->reg == 0
  || locate->partial != 0
  || locate->pass_on_stack)
{
  if (crtl->stack_alignment_needed < locate->boundary)
crtl->stack_alignment_needed = locate->boundary;
  if (crtl->preferred_stack_boundary < locate->boundary)
crtl->preferred_stack_boundary = locate->boundary;
}
}

OK with that change, thanks.

Richard


V3: [PATCH] Update preferred_stack_boundary only when expanding function call

2019-06-13 Thread H.J. Lu
On Sat, Jun 8, 2019 at 12:14 AM Richard Sandiford
 wrote:
>
> "H.J. Lu"  writes:
> > On Fri, Jun 7, 2019 at 1:22 AM Richard Biener  wrote:
> >>
> >> On Fri, 7 Jun 2019, Richard Sandiford wrote:
> >>
> >> > "H.J. Lu"  writes:
> >> > > locate_and_pad_parm is called when expanding function call from
> >> > > initialize_argument_information and when generating function body
> >> > > from assign_parm_find_entry_rtl:
> >> > >
> >> > >   /* Remember if the outgoing parameter requires extra alignment on the
> >> > >  calling function side.  */
> >> > >   if (crtl->stack_alignment_needed < boundary)
> >> > > crtl->stack_alignment_needed = boundary;
> >> > >   if (crtl->preferred_stack_boundary < boundary)
> >> > > crtl->preferred_stack_boundary = boundary;
> >> > >
> >> > > stack_alignment_needed and preferred_stack_boundary should be updated
> >> > > only when expanding function call, not when generating function body.
> >> > > Add an argument, outgoing_p, to locate_and_pad_parm to indicate for
> >> > > expanding function call.  Update stack_alignment_needed and
> >> > > preferred_stack_boundary if the parameter is passed on stack and only
> >> > > when expanding function call.
> >> > >
> >> > > Tested on Linux/x86-64.
> >> > >
> >> > > OK for trunk?
> >> > >
> >> > > Thanks.
> >> > >
> >> > > --
> >> > > H.J.
> >> > >
> >> > > From e91e20ad8e10373db2c6d8f99a3da0bbf46c5c34 Mon Sep 17 00:00:00 2001
> >> > > From: "H.J. Lu" 
> >> > > Date: Wed, 5 Jun 2019 12:55:19 -0700
> >> > > Subject: [PATCH] Update preferred_stack_boundary only when expanding 
> >> > > function
> >> > >  call
> >> > >
> >> > > locate_and_pad_parm is called when expanding function call from
> >> > > initialize_argument_information and when generating function body
> >> > > from assign_parm_find_entry_rtl:
> >> > >
> >> > >   /* Remember if the outgoing parameter requires extra alignment on the
> >> > >  calling function side.  */
> >> > >   if (crtl->stack_alignment_needed < boundary)
> >> > > crtl->stack_alignment_needed = boundary;
> >> > >   if (crtl->preferred_stack_boundary < boundary)
> >> > > crtl->preferred_stack_boundary = boundary;
> >> > >
> >> > > stack_alignment_needed and preferred_stack_boundary should be updated
> >> > > only when expanding function call, not when generating function body.
> >> > > Add an argument, outgoing_p, to locate_and_pad_parm to indicate for
> >> > > expanding function call.  Update stack_alignment_needed and
> >> > > preferred_stack_boundary if the parameter is passed on stack and only
> >> > > when expanding function call.
> >> > >
> >> > > Tested on Linux/x86-64.
> >> > >
> >> > > gcc/
> >> > >
> >> > > PR rtl-optimization/90765
> >> > > * function.c (assign_parm_find_entry_rtl): Pass false to
> >> > > locate_and_pad_parm.
> >> > > (locate_and_pad_parm): Add an argument, outgoing_p, to indicate
> >> > > for expanding function call.  Update stack_alignment_needed and
> >> > > preferred_stack_boundary only if outgoing_p is true and the
> >> > > the parameter is passed on stack.
> >> > > * function.h (locate_and_pad_parm): Add an argument, outgoing_p,
> >> > > defaulting to true.
> >> > >
> >> > > gcc/testsuite/
> >> > >
> >> > > PR rtl-optimization/90765
> >> > > * gcc.target/i386/pr90765-1.c: New test.
> >> > > * gcc.target/i386/pr90765-2.c: Likewise.
> >> > > ---
> >> > >  gcc/function.c| 21 +
> >> > >  gcc/function.h|  3 ++-
> >> > >  gcc/testsuite/gcc.target/i386/pr90765-1.c | 11 +++
> >> > >  gcc/testsuite/gcc.target/i386/pr90765-2.c | 18 ++
> >> > >  4 files changed, 44 inser

Re: V2: [PATCH] Update preferred_stack_boundary only when expanding function call

2019-06-08 Thread Richard Sandiford
"H.J. Lu"  writes:
> On Fri, Jun 7, 2019 at 1:22 AM Richard Biener  wrote:
>>
>> On Fri, 7 Jun 2019, Richard Sandiford wrote:
>>
>> > "H.J. Lu"  writes:
>> > > locate_and_pad_parm is called when expanding function call from
>> > > initialize_argument_information and when generating function body
>> > > from assign_parm_find_entry_rtl:
>> > >
>> > >   /* Remember if the outgoing parameter requires extra alignment on the
>> > >  calling function side.  */
>> > >   if (crtl->stack_alignment_needed < boundary)
>> > > crtl->stack_alignment_needed = boundary;
>> > >   if (crtl->preferred_stack_boundary < boundary)
>> > > crtl->preferred_stack_boundary = boundary;
>> > >
>> > > stack_alignment_needed and preferred_stack_boundary should be updated
>> > > only when expanding function call, not when generating function body.
>> > > Add an argument, outgoing_p, to locate_and_pad_parm to indicate for
>> > > expanding function call.  Update stack_alignment_needed and
>> > > preferred_stack_boundary if the parameter is passed on stack and only
>> > > when expanding function call.
>> > >
>> > > Tested on Linux/x86-64.
>> > >
>> > > OK for trunk?
>> > >
>> > > Thanks.
>> > >
>> > > --
>> > > H.J.
>> > >
>> > > From e91e20ad8e10373db2c6d8f99a3da0bbf46c5c34 Mon Sep 17 00:00:00 2001
>> > > From: "H.J. Lu" 
>> > > Date: Wed, 5 Jun 2019 12:55:19 -0700
>> > > Subject: [PATCH] Update preferred_stack_boundary only when expanding 
>> > > function
>> > >  call
>> > >
>> > > locate_and_pad_parm is called when expanding function call from
>> > > initialize_argument_information and when generating function body
>> > > from assign_parm_find_entry_rtl:
>> > >
>> > >   /* Remember if the outgoing parameter requires extra alignment on the
>> > >  calling function side.  */
>> > >   if (crtl->stack_alignment_needed < boundary)
>> > > crtl->stack_alignment_needed = boundary;
>> > >   if (crtl->preferred_stack_boundary < boundary)
>> > > crtl->preferred_stack_boundary = boundary;
>> > >
>> > > stack_alignment_needed and preferred_stack_boundary should be updated
>> > > only when expanding function call, not when generating function body.
>> > > Add an argument, outgoing_p, to locate_and_pad_parm to indicate for
>> > > expanding function call.  Update stack_alignment_needed and
>> > > preferred_stack_boundary if the parameter is passed on stack and only
>> > > when expanding function call.
>> > >
>> > > Tested on Linux/x86-64.
>> > >
>> > > gcc/
>> > >
>> > > PR rtl-optimization/90765
>> > > * function.c (assign_parm_find_entry_rtl): Pass false to
>> > > locate_and_pad_parm.
>> > > (locate_and_pad_parm): Add an argument, outgoing_p, to indicate
>> > > for expanding function call.  Update stack_alignment_needed and
>> > > preferred_stack_boundary only if outgoing_p is true and the
>> > > the parameter is passed on stack.
>> > > * function.h (locate_and_pad_parm): Add an argument, outgoing_p,
>> > > defaulting to true.
>> > >
>> > > gcc/testsuite/
>> > >
>> > > PR rtl-optimization/90765
>> > > * gcc.target/i386/pr90765-1.c: New test.
>> > > * gcc.target/i386/pr90765-2.c: Likewise.
>> > > ---
>> > >  gcc/function.c| 21 +
>> > >  gcc/function.h|  3 ++-
>> > >  gcc/testsuite/gcc.target/i386/pr90765-1.c | 11 +++
>> > >  gcc/testsuite/gcc.target/i386/pr90765-2.c | 18 ++
>> > >  4 files changed, 44 insertions(+), 9 deletions(-)
>> > >  create mode 100644 gcc/testsuite/gcc.target/i386/pr90765-1.c
>> > >  create mode 100644 gcc/testsuite/gcc.target/i386/pr90765-2.c
>> > >
>> > > diff --git a/gcc/function.c b/gcc/function.c
>> > > index e30ee259bec..9b6673f6f0d 100644
>> > > --- a/gcc/function.c
>> > > +++ b/gcc/function.c
>> > > @@ -2601,7 +2601,7 @@ assign_parm_find_entry_

V2: [PATCH] Update preferred_stack_boundary only when expanding function call

2019-06-07 Thread H.J. Lu
On Fri, Jun 7, 2019 at 1:22 AM Richard Biener  wrote:
>
> On Fri, 7 Jun 2019, Richard Sandiford wrote:
>
> > "H.J. Lu"  writes:
> > > locate_and_pad_parm is called when expanding function call from
> > > initialize_argument_information and when generating function body
> > > from assign_parm_find_entry_rtl:
> > >
> > >   /* Remember if the outgoing parameter requires extra alignment on the
> > >  calling function side.  */
> > >   if (crtl->stack_alignment_needed < boundary)
> > > crtl->stack_alignment_needed = boundary;
> > >   if (crtl->preferred_stack_boundary < boundary)
> > > crtl->preferred_stack_boundary = boundary;
> > >
> > > stack_alignment_needed and preferred_stack_boundary should be updated
> > > only when expanding function call, not when generating function body.
> > > Add an argument, outgoing_p, to locate_and_pad_parm to indicate for
> > > expanding function call.  Update stack_alignment_needed and
> > > preferred_stack_boundary if the parameter is passed on stack and only
> > > when expanding function call.
> > >
> > > Tested on Linux/x86-64.
> > >
> > > OK for trunk?
> > >
> > > Thanks.
> > >
> > > --
> > > H.J.
> > >
> > > From e91e20ad8e10373db2c6d8f99a3da0bbf46c5c34 Mon Sep 17 00:00:00 2001
> > > From: "H.J. Lu" 
> > > Date: Wed, 5 Jun 2019 12:55:19 -0700
> > > Subject: [PATCH] Update preferred_stack_boundary only when expanding 
> > > function
> > >  call
> > >
> > > locate_and_pad_parm is called when expanding function call from
> > > initialize_argument_information and when generating function body
> > > from assign_parm_find_entry_rtl:
> > >
> > >   /* Remember if the outgoing parameter requires extra alignment on the
> > >  calling function side.  */
> > >   if (crtl->stack_alignment_needed < boundary)
> > > crtl->stack_alignment_needed = boundary;
> > >   if (crtl->preferred_stack_boundary < boundary)
> > > crtl->preferred_stack_boundary = boundary;
> > >
> > > stack_alignment_needed and preferred_stack_boundary should be updated
> > > only when expanding function call, not when generating function body.
> > > Add an argument, outgoing_p, to locate_and_pad_parm to indicate for
> > > expanding function call.  Update stack_alignment_needed and
> > > preferred_stack_boundary if the parameter is passed on stack and only
> > > when expanding function call.
> > >
> > > Tested on Linux/x86-64.
> > >
> > > gcc/
> > >
> > > PR rtl-optimization/90765
> > > * function.c (assign_parm_find_entry_rtl): Pass false to
> > > locate_and_pad_parm.
> > > (locate_and_pad_parm): Add an argument, outgoing_p, to indicate
> > > for expanding function call.  Update stack_alignment_needed and
> > > preferred_stack_boundary only if outgoing_p is true and the
> > > the parameter is passed on stack.
> > > * function.h (locate_and_pad_parm): Add an argument, outgoing_p,
> > > defaulting to true.
> > >
> > > gcc/testsuite/
> > >
> > > PR rtl-optimization/90765
> > > * gcc.target/i386/pr90765-1.c: New test.
> > > * gcc.target/i386/pr90765-2.c: Likewise.
> > > ---
> > >  gcc/function.c| 21 +
> > >  gcc/function.h|  3 ++-
> > >  gcc/testsuite/gcc.target/i386/pr90765-1.c | 11 +++
> > >  gcc/testsuite/gcc.target/i386/pr90765-2.c | 18 ++
> > >  4 files changed, 44 insertions(+), 9 deletions(-)
> > >  create mode 100644 gcc/testsuite/gcc.target/i386/pr90765-1.c
> > >  create mode 100644 gcc/testsuite/gcc.target/i386/pr90765-2.c
> > >
> > > diff --git a/gcc/function.c b/gcc/function.c
> > > index e30ee259bec..9b6673f6f0d 100644
> > > --- a/gcc/function.c
> > > +++ b/gcc/function.c
> > > @@ -2601,7 +2601,7 @@ assign_parm_find_entry_rtl (struct 
> > > assign_parm_data_all *all,
> > >locate_and_pad_parm (data->promoted_mode, data->passed_type, in_regs,
> > >all->reg_parm_stack_space,
> > >entry_parm ? data->partial : 0, current_function_decl,
> > > -  >stack_args_size, >locate);
> > > +  

Re: [PATCH] Update preferred_stack_boundary only when expanding function call

2019-06-07 Thread Richard Biener
On Fri, 7 Jun 2019, Richard Sandiford wrote:

> "H.J. Lu"  writes:
> > locate_and_pad_parm is called when expanding function call from
> > initialize_argument_information and when generating function body
> > from assign_parm_find_entry_rtl:
> >
> >   /* Remember if the outgoing parameter requires extra alignment on the
> >  calling function side.  */
> >   if (crtl->stack_alignment_needed < boundary)
> > crtl->stack_alignment_needed = boundary;
> >   if (crtl->preferred_stack_boundary < boundary)
> > crtl->preferred_stack_boundary = boundary;
> >
> > stack_alignment_needed and preferred_stack_boundary should be updated
> > only when expanding function call, not when generating function body.
> > Add an argument, outgoing_p, to locate_and_pad_parm to indicate for
> > expanding function call.  Update stack_alignment_needed and
> > preferred_stack_boundary if the parameter is passed on stack and only
> > when expanding function call.
> >
> > Tested on Linux/x86-64.
> >
> > OK for trunk?
> >
> > Thanks.
> >
> > -- 
> > H.J.
> >
> > From e91e20ad8e10373db2c6d8f99a3da0bbf46c5c34 Mon Sep 17 00:00:00 2001
> > From: "H.J. Lu" 
> > Date: Wed, 5 Jun 2019 12:55:19 -0700
> > Subject: [PATCH] Update preferred_stack_boundary only when expanding 
> > function
> >  call
> >
> > locate_and_pad_parm is called when expanding function call from
> > initialize_argument_information and when generating function body
> > from assign_parm_find_entry_rtl:
> >
> >   /* Remember if the outgoing parameter requires extra alignment on the
> >  calling function side.  */
> >   if (crtl->stack_alignment_needed < boundary)
> > crtl->stack_alignment_needed = boundary;
> >   if (crtl->preferred_stack_boundary < boundary)
> > crtl->preferred_stack_boundary = boundary;
> >
> > stack_alignment_needed and preferred_stack_boundary should be updated
> > only when expanding function call, not when generating function body.
> > Add an argument, outgoing_p, to locate_and_pad_parm to indicate for
> > expanding function call.  Update stack_alignment_needed and
> > preferred_stack_boundary if the parameter is passed on stack and only
> > when expanding function call.
> >
> > Tested on Linux/x86-64.
> >
> > gcc/
> >
> > PR rtl-optimization/90765
> > * function.c (assign_parm_find_entry_rtl): Pass false to
> > locate_and_pad_parm.
> > (locate_and_pad_parm): Add an argument, outgoing_p, to indicate
> > for expanding function call.  Update stack_alignment_needed and
> > preferred_stack_boundary only if outgoing_p is true and the
> > the parameter is passed on stack.
> > * function.h (locate_and_pad_parm): Add an argument, outgoing_p,
> > defaulting to true.
> >
> > gcc/testsuite/
> >
> > PR rtl-optimization/90765
> > * gcc.target/i386/pr90765-1.c: New test.
> > * gcc.target/i386/pr90765-2.c: Likewise.
> > ---
> >  gcc/function.c| 21 +
> >  gcc/function.h|  3 ++-
> >  gcc/testsuite/gcc.target/i386/pr90765-1.c | 11 +++
> >  gcc/testsuite/gcc.target/i386/pr90765-2.c | 18 ++
> >  4 files changed, 44 insertions(+), 9 deletions(-)
> >  create mode 100644 gcc/testsuite/gcc.target/i386/pr90765-1.c
> >  create mode 100644 gcc/testsuite/gcc.target/i386/pr90765-2.c
> >
> > diff --git a/gcc/function.c b/gcc/function.c
> > index e30ee259bec..9b6673f6f0d 100644
> > --- a/gcc/function.c
> > +++ b/gcc/function.c
> > @@ -2601,7 +2601,7 @@ assign_parm_find_entry_rtl (struct 
> > assign_parm_data_all *all,
> >locate_and_pad_parm (data->promoted_mode, data->passed_type, in_regs,
> >all->reg_parm_stack_space,
> >entry_parm ? data->partial : 0, current_function_decl,
> > -  >stack_args_size, >locate);
> > +  >stack_args_size, >locate, false);
> >  
> >/* Update parm_stack_boundary if this parameter is passed in the
> >   stack.  */
> > @@ -3954,7 +3954,8 @@ locate_and_pad_parm (machine_mode passed_mode, tree 
> > type, int in_regs,
> >  int reg_parm_stack_space, int partial,
> >  tree fndecl ATTRIBUTE_UNUSED,
> >  struct args_size *initial_offset_ptr,
> > -struct locate_and_pad_arg_data *locate

Re: [PATCH] Update preferred_stack_boundary only when expanding function call

2019-06-07 Thread Richard Sandiford
"H.J. Lu"  writes:
> locate_and_pad_parm is called when expanding function call from
> initialize_argument_information and when generating function body
> from assign_parm_find_entry_rtl:
>
>   /* Remember if the outgoing parameter requires extra alignment on the
>  calling function side.  */
>   if (crtl->stack_alignment_needed < boundary)
> crtl->stack_alignment_needed = boundary;
>   if (crtl->preferred_stack_boundary < boundary)
> crtl->preferred_stack_boundary = boundary;
>
> stack_alignment_needed and preferred_stack_boundary should be updated
> only when expanding function call, not when generating function body.
> Add an argument, outgoing_p, to locate_and_pad_parm to indicate for
> expanding function call.  Update stack_alignment_needed and
> preferred_stack_boundary if the parameter is passed on stack and only
> when expanding function call.
>
> Tested on Linux/x86-64.
>
> OK for trunk?
>
> Thanks.
>
> -- 
> H.J.
>
> From e91e20ad8e10373db2c6d8f99a3da0bbf46c5c34 Mon Sep 17 00:00:00 2001
> From: "H.J. Lu" 
> Date: Wed, 5 Jun 2019 12:55:19 -0700
> Subject: [PATCH] Update preferred_stack_boundary only when expanding function
>  call
>
> locate_and_pad_parm is called when expanding function call from
> initialize_argument_information and when generating function body
> from assign_parm_find_entry_rtl:
>
>   /* Remember if the outgoing parameter requires extra alignment on the
>  calling function side.  */
>   if (crtl->stack_alignment_needed < boundary)
> crtl->stack_alignment_needed = boundary;
>   if (crtl->preferred_stack_boundary < boundary)
> crtl->preferred_stack_boundary = boundary;
>
> stack_alignment_needed and preferred_stack_boundary should be updated
> only when expanding function call, not when generating function body.
> Add an argument, outgoing_p, to locate_and_pad_parm to indicate for
> expanding function call.  Update stack_alignment_needed and
> preferred_stack_boundary if the parameter is passed on stack and only
> when expanding function call.
>
> Tested on Linux/x86-64.
>
> gcc/
>
>   PR rtl-optimization/90765
>   * function.c (assign_parm_find_entry_rtl): Pass false to
>   locate_and_pad_parm.
>   (locate_and_pad_parm): Add an argument, outgoing_p, to indicate
>   for expanding function call.  Update stack_alignment_needed and
>   preferred_stack_boundary only if outgoing_p is true and the
>   the parameter is passed on stack.
>   * function.h (locate_and_pad_parm): Add an argument, outgoing_p,
>   defaulting to true.
>
> gcc/testsuite/
>
>   PR rtl-optimization/90765
>   * gcc.target/i386/pr90765-1.c: New test.
>   * gcc.target/i386/pr90765-2.c: Likewise.
> ---
>  gcc/function.c| 21 +
>  gcc/function.h|  3 ++-
>  gcc/testsuite/gcc.target/i386/pr90765-1.c | 11 +++
>  gcc/testsuite/gcc.target/i386/pr90765-2.c | 18 ++
>  4 files changed, 44 insertions(+), 9 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr90765-1.c
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr90765-2.c
>
> diff --git a/gcc/function.c b/gcc/function.c
> index e30ee259bec..9b6673f6f0d 100644
> --- a/gcc/function.c
> +++ b/gcc/function.c
> @@ -2601,7 +2601,7 @@ assign_parm_find_entry_rtl (struct assign_parm_data_all 
> *all,
>locate_and_pad_parm (data->promoted_mode, data->passed_type, in_regs,
>  all->reg_parm_stack_space,
>  entry_parm ? data->partial : 0, current_function_decl,
> ->stack_args_size, >locate);
> +>stack_args_size, >locate, false);
>  
>/* Update parm_stack_boundary if this parameter is passed in the
>   stack.  */
> @@ -3954,7 +3954,8 @@ locate_and_pad_parm (machine_mode passed_mode, tree 
> type, int in_regs,
>int reg_parm_stack_space, int partial,
>tree fndecl ATTRIBUTE_UNUSED,
>struct args_size *initial_offset_ptr,
> -  struct locate_and_pad_arg_data *locate)
> +  struct locate_and_pad_arg_data *locate,
> +  bool outgoing_p)
>  {
>tree sizetree;
>pad_direction where_pad;
> @@ -4021,12 +4022,16 @@ locate_and_pad_parm (machine_mode passed_mode, tree 
> type, int in_regs,
>   }
>  }
>  
> -  /* Remember if the outgoing parameter requires extra alignment on the
> - calling function side.  */
> -  if (crtl->stack_alignment_needed < boundary)
> -crtl->stack_

[PATCH] Update preferred_stack_boundary only when expanding function call

2019-06-06 Thread H.J. Lu
locate_and_pad_parm is called when expanding function call from
initialize_argument_information and when generating function body
from assign_parm_find_entry_rtl:

  /* Remember if the outgoing parameter requires extra alignment on the
 calling function side.  */
  if (crtl->stack_alignment_needed < boundary)
crtl->stack_alignment_needed = boundary;
  if (crtl->preferred_stack_boundary < boundary)
crtl->preferred_stack_boundary = boundary;

stack_alignment_needed and preferred_stack_boundary should be updated
only when expanding function call, not when generating function body.
Add an argument, outgoing_p, to locate_and_pad_parm to indicate for
expanding function call.  Update stack_alignment_needed and
preferred_stack_boundary if the parameter is passed on stack and only
when expanding function call.

Tested on Linux/x86-64.

OK for trunk?

Thanks.

-- 
H.J.
From e91e20ad8e10373db2c6d8f99a3da0bbf46c5c34 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" 
Date: Wed, 5 Jun 2019 12:55:19 -0700
Subject: [PATCH] Update preferred_stack_boundary only when expanding function
 call

locate_and_pad_parm is called when expanding function call from
initialize_argument_information and when generating function body
from assign_parm_find_entry_rtl:

  /* Remember if the outgoing parameter requires extra alignment on the
 calling function side.  */
  if (crtl->stack_alignment_needed < boundary)
crtl->stack_alignment_needed = boundary;
  if (crtl->preferred_stack_boundary < boundary)
crtl->preferred_stack_boundary = boundary;

stack_alignment_needed and preferred_stack_boundary should be updated
only when expanding function call, not when generating function body.
Add an argument, outgoing_p, to locate_and_pad_parm to indicate for
expanding function call.  Update stack_alignment_needed and
preferred_stack_boundary if the parameter is passed on stack and only
when expanding function call.

Tested on Linux/x86-64.

gcc/

	PR rtl-optimization/90765
	* function.c (assign_parm_find_entry_rtl): Pass false to
	locate_and_pad_parm.
	(locate_and_pad_parm): Add an argument, outgoing_p, to indicate
	for expanding function call.  Update stack_alignment_needed and
	preferred_stack_boundary only if outgoing_p is true and the
	the parameter is passed on stack.
	* function.h (locate_and_pad_parm): Add an argument, outgoing_p,
	defaulting to true.

gcc/testsuite/

	PR rtl-optimization/90765
	* gcc.target/i386/pr90765-1.c: New test.
	* gcc.target/i386/pr90765-2.c: Likewise.
---
 gcc/function.c| 21 +
 gcc/function.h|  3 ++-
 gcc/testsuite/gcc.target/i386/pr90765-1.c | 11 +++
 gcc/testsuite/gcc.target/i386/pr90765-2.c | 18 ++
 4 files changed, 44 insertions(+), 9 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr90765-1.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr90765-2.c

diff --git a/gcc/function.c b/gcc/function.c
index e30ee259bec..9b6673f6f0d 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -2601,7 +2601,7 @@ assign_parm_find_entry_rtl (struct assign_parm_data_all *all,
   locate_and_pad_parm (data->promoted_mode, data->passed_type, in_regs,
 		   all->reg_parm_stack_space,
 		   entry_parm ? data->partial : 0, current_function_decl,
-		   >stack_args_size, >locate);
+		   >stack_args_size, >locate, false);
 
   /* Update parm_stack_boundary if this parameter is passed in the
  stack.  */
@@ -3954,7 +3954,8 @@ locate_and_pad_parm (machine_mode passed_mode, tree type, int in_regs,
 		 int reg_parm_stack_space, int partial,
 		 tree fndecl ATTRIBUTE_UNUSED,
 		 struct args_size *initial_offset_ptr,
-		 struct locate_and_pad_arg_data *locate)
+		 struct locate_and_pad_arg_data *locate,
+		 bool outgoing_p)
 {
   tree sizetree;
   pad_direction where_pad;
@@ -4021,12 +4022,16 @@ locate_and_pad_parm (machine_mode passed_mode, tree type, int in_regs,
 	}
 }
 
-  /* Remember if the outgoing parameter requires extra alignment on the
- calling function side.  */
-  if (crtl->stack_alignment_needed < boundary)
-crtl->stack_alignment_needed = boundary;
-  if (crtl->preferred_stack_boundary < boundary)
-crtl->preferred_stack_boundary = boundary;
+  if (outgoing_p && !in_regs)
+{
+  /* Remember if the outgoing parameter requires extra alignment on
+	 the calling function side if this parameter is passed in the
+	 stack.  */
+  if (crtl->stack_alignment_needed < boundary)
+	crtl->stack_alignment_needed = boundary;
+  if (crtl->preferred_stack_boundary < boundary)
+	crtl->preferred_stack_boundary = boundary;
+}
 
   if (ARGS_GROW_DOWNWARD)
 {
diff --git a/gcc/function.h b/gcc/function.h
index bfe9919a760..5ad7a33fd39 100644
--- a/gcc/function.h
+++ b/gcc/function.h
@@ -613,7 +613,8 @@ extern bool use_regis