From: Max Filippov <jcmvbkbc@gmail.com>
To: "Takayuki 'January June' Suwa" <jjsuwa_sys3175@yahoo.co.jp>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH v3 1/2] xtensa: Eliminate unused stack frame allocation/freeing
Date: Wed, 7 Sep 2022 07:55:58 -0700 [thread overview]
Message-ID: <CAMo8BfJt7Rt-ctNns=2yh3T4C3rJy_tidT8e+NuKHet-S_u7sg@mail.gmail.com> (raw)
In-Reply-To: <dba5c3f2-8b2a-c593-6f0d-a5846153d734@yahoo.co.jp>
Hi Suwa-san,
On Wed, Sep 7, 2022 at 2:08 AM Takayuki 'January June' Suwa
<jjsuwa_sys3175@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
prev parent reply other threads:[~2022-09-07 14:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-07 9:08 Takayuki 'January June' Suwa
2022-09-07 14:55 ` Max Filippov [this message]
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='CAMo8BfJt7Rt-ctNns=2yh3T4C3rJy_tidT8e+NuKHet-S_u7sg@mail.gmail.com' \
--to=jcmvbkbc@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jjsuwa_sys3175@yahoo.co.jp \
/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).