On Thu, Sep 8, 2022 at 2:38 PM Takayuki 'January June' Suwa
<jjsuwa_sys3...@yahoo.co.jp> wrote:
>
> Changes from v3:
>   (xtensa_expand_prologue): Changed to exclude debug insns from DF use chain 
> analysis.
>
> ---
>
> 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 | 164 ++++++++++++++++++------------------
>  1 file changed, 80 insertions(+), 84 deletions(-)

Regtested for target=xtensa-linux-uclibc, no new regressions.
Committed to master.

-- 
Thanks.
-- Max

Reply via email to