public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Takayuki 'January June' Suwa <jjsuwa_sys3175@yahoo.co.jp>
To: Max Filippov <jcmvbkbc@gmail.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] xtensa: Optimize stack frame adjustment more
Date: Fri, 6 Jan 2023 12:34:59 +0900	[thread overview]
Message-ID: <bcef8fa4-88cf-f7d6-44b0-fe1efe089fd1@yahoo.co.jp> (raw)
In-Reply-To: <CAMo8BfJcOoGWjHPzPVzE8RmzBpu6fYVpA6SW1gPsfF36MG5bJw@mail.gmail.com>

On 2023/01/06 6:32, Max Filippov wrote:
> Hi Suwa-san,
Hi!

> 
> On Thu, Jan 5, 2023 at 3:57 AM Takayuki 'January June' Suwa
> <jjsuwa_sys3175@yahoo.co.jp> wrote:
>>
>> This patch introduces a convenient helper function for integer immediate
>> addition with scratch register as needed, that splits and emits either
>> up to two ADDI/ADDMI machine instructions or an addition by register
>> following an immediate integer load (which may later be transformed by
>> constantsynth).
>>
>> By using the helper function, it makes stack frame adjustment logic
>> simplified and instruction count less in some cases.
>>
>> gcc/ChangeLog:
>>
>>         * config/xtensa/xtensa.cc
>>         (xtensa_split_imm_two_addends, xtensa_emit_add_imm):
>>         New helper functions.
>>         (xtensa_emit_adjust_stack_ptr, xtensa_set_return_address,
>>         xtensa_output_mi_thunk): Change to use the helper function.
>> ---
>>  gcc/config/xtensa/xtensa.cc | 139 +++++++++++++++++++++++-------------
>>  1 file changed, 88 insertions(+), 51 deletions(-)
> 
> This change introduces a bunch of failures in the g++ testsuite,
> but the culprit is apparently somewhere in the libstdc++.so, I'm
> still looking for it.
> 
> I see the following pattern change in the generated epilogue code:
> 
> -    4aaf:      b0a192          movi    a9, 0x1b0
> -    4ab2:      1f9a            add.n   a1, a15, a9
> ...
> -    4abe:      20c112          addi    a1, a1, 32
> -    4ac1:      f00d            ret.n
> +    4aaf:      02df12          addmi   a1, a15, 0x200
> +    4ab2:      b0c112          addi    a1, a1, -80
> ...
> +    4abf:      20c112          addi    a1, a1, 32
> +    4ac2:      f00d            ret.n
> 
> I.e. a1 is first moved into the parent stack frame, then back to the right
> spot. This does not look correct, especially for bare-metal targets.
> 

On second thought, it cannot be a good idea to split addition/subtraction to the stack pointer.

> -    4aaf:      b0a192          movi    a9, 0x1b0
> -    4ab2:      1f9a            add.n   a1, a15, a9

> +    4aaf:      02df12          addmi   a1, a15, 0x200
> +    4ab2:      b0c112          addi    a1, a1, -80

Because the former is atomic, but the latter is not. (may be interrupted between the two add instructions)

I'll wait for the results of your investigation, but it may be better to withdraw the patch.

  reply	other threads:[~2023-01-06  3:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <04a89dbf-c2a3-5dcb-8949-77569a1ad169.ref@yahoo.co.jp>
2023-01-05  8:40 ` Takayuki 'January June' Suwa
2023-01-05 21:32   ` Max Filippov
2023-01-06  3:34     ` Takayuki 'January June' Suwa [this message]
2023-01-06  6:26       ` Max Filippov
2023-01-06  6:57         ` Takayuki 'January June' Suwa
2023-01-06  8:05           ` Max Filippov
2023-01-07  2:54             ` Takayuki 'January June' Suwa

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=bcef8fa4-88cf-f7d6-44b0-fe1efe089fd1@yahoo.co.jp \
    --to=jjsuwa_sys3175@yahoo.co.jp \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jcmvbkbc@gmail.com \
    /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).