Hi Suwa-san,

On Wed, Sep 7, 2022 at 2:08 AM Takayuki 'January June' Suwa
<jjsuwa_sys3...@yahoo.co.jp> wrote:
>
> Changes from v2:
>   (xtensa_expand_prologue): Changed to check conditions for suppressing emit 
> insns in advance, instead of tracking emitted and later replacing them with 
> NOPs if they are found to be unnecessary.
>
> ---
>
> In the example below, 'x' is once placed on the stack frame and then read
> into registers as the argument value of bar():
>
>     /* example */
>     struct foo {
>       int a, b;
>     };
>     extern struct foo bar(struct foo);
>     struct foo test(void) {
>       struct foo x = { 0, 1 };
>       return bar(x);
>     }
>
> Thanks to the dead store elimination, the initialization of 'x' turns into
> merely loading the immediates to registers, but corresponding stack frame
> growth is not rolled back.  As a result:
>
>     ;; prereq: the CALL0 ABI
>     ;; before
>     test:
>         addi    sp, sp, -16     // unused stack frame allocation/freeing
>         movi.n  a2, 0
>         movi.n  a3, 1
>         addi    sp, sp, 16      // because no instructions that refer to
>         j.l     bar, a9         // the stack pointer between the two
>
> This patch eliminates such unused stack frame allocation/freeing:
>
>     ;; after
>     test:
>         movi.n  a2, 0
>         movi.n  a3, 1
>         j.l     bar, a9
>
> gcc/ChangeLog:
>
>         * config/xtensa/xtensa.cc (machine_function): New boolean member as
>         a flag that controls whether to emit the insns for stack pointer
>         adjustment inside of the pro/epilogue.
>         (xtensa_emit_adjust_stack_ptr): New function to share the common
>         codes and to emit insns if not inhibited.
>         (xtensa_expand_epilogue): Change to use the function mentioned
>         above when using the CALL0 ABI.
>         (xtensa_expand_prologue): Ditto.
>         And also change to set the inhibit flag used by
>         xtensa_emit_adjust_stack_ptr() to true if the stack pointer is only
>         used for its own adjustment.
> ---
>  gcc/config/xtensa/xtensa.cc | 162 +++++++++++++++++-------------------
>  1 file changed, 78 insertions(+), 84 deletions(-)

There's still a minor issue here: this change introduces a new regression
in the following test:
g++.dg/opt/pr100469.C

AFAICS it generates different code with and without the '-g' option: no
stack modification without -g, but adjustment in prologue and epilogue
with -g.

-- 
Thanks.
-- Max

Reply via email to