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] xtensa: Optimize boolean evaluation or branching when EQ/NE to INT_MIN
Date: Sun, 4 Jun 2023 10:13:27 -0700 [thread overview]
Message-ID: <CAMo8Bf+Mm8L0u3Rk6BzKQn8cAEqvnXUJapP3GyKNcmCEBxDJ9g@mail.gmail.com> (raw)
In-Reply-To: <eb2b819e-5cf4-e71f-2cb3-b05046f18de8@yahoo.co.jp>
On Sat, Jun 3, 2023 at 3:52 PM Takayuki 'January June' Suwa
<jjsuwa_sys3175@yahoo.co.jp> wrote:
>
> This patch optimizes both the boolean evaluation of and the branching of
> EQ/NE against INT_MIN (-2147483648), by taking advantage of the specifi-
> cation the ABS machine instruction on Xtensa returns INT_MIN iff INT_MIN,
> otherwise non-negative value.
>
> /* example */
> int test0(int x) {
> return (x == -2147483648);
> }
> int test1(int x) {
> return (x != -2147483648);
> }
> extern void foo(void);
> void test2(int x) {
> if(x == -2147483648)
> foo();
> }
> void test3(int x) {
> if(x != -2147483648)
> foo();
> }
>
> ;; before
> test0:
> movi.n a9, -1
> slli a9, a9, 31
> add.n a2, a2, a9
> nsau a2, a2
> srli a2, a2, 5
> ret.n
> test1:
> movi.n a9, -1
> slli a9, a9, 31
> add.n a9, a2, a9
> movi.n a2, 1
> moveqz a2, a9, a9
> ret.n
> test2:
> movi.n a9, -1
> slli a9, a9, 31
> bne a2, a9, .L3
> j.l foo, a9
> .L3:
> ret.n
> test3:
> movi.n a9, -1
> slli a9, a9, 31
> beq a2, a9, .L5
> j.l foo, a9
> .L5:
> ret.n
>
> ;; after
> test0:
> abs a2, a2
> extui a2, a2, 31, 1
> ret.n
> test1:
> abs a2, a2
> srai a2, a2, 31
> addi.n a2, a2, 1
> ret.n
> test2:
> abs a2, a2
> bbci a2, 31, .L3
> j.l foo, a9
> .L3:
> ret.n
> test3:
> abs a2, a2
> bbsi a2, 31, .L5
> j.l foo, a9
> .L5:
> ret.n
>
> gcc/ChangeLog:
>
> * config/xtensa/xtensa.md (*btrue_INT_MIN, *eqne_INT_MIN):
> New insn_and_split patterns.
> ---
> gcc/config/xtensa/xtensa.md | 64 +++++++++++++++++++++++++++++++++++++
> 1 file changed, 64 insertions(+)
Regtested for target=xtensa-linux-uclibc, no new regressions.
Committed to master.
--
Thanks.
-- Max
prev parent reply other threads:[~2023-06-04 17:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <eb2b819e-5cf4-e71f-2cb3-b05046f18de8.ref@yahoo.co.jp>
2023-06-03 22:52 ` Takayuki 'January June' Suwa
2023-06-03 23:03 ` Andrew Pinski
2023-06-04 3:06 ` Jeff Law
2023-06-04 17:13 ` 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=CAMo8Bf+Mm8L0u3Rk6BzKQn8cAEqvnXUJapP3GyKNcmCEBxDJ9g@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).