public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Waterman <andrew@sifive.com>
To: Jivan Hakobyan <jivanhakobyan9@gmail.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: RISC-V: Replace not + bitwise_imm with li + bitwise_not
Date: Mon, 11 Sep 2023 12:16:49 -0700	[thread overview]
Message-ID: <CA++6G0Do5=frLfEeG72a9ozmx6PVaqBtWcDquo7THEJHfHdxAQ@mail.gmail.com> (raw)
In-Reply-To: <CAHso6sM7F5ffvnEfFwNp0EozHTd1_YCK-4LhC7i-3HkPEZy+1Q@mail.gmail.com>

Note this is a size-speed tradeoff, as the Zcb extension has a
16-bit-wide C.NOT instruction.  Might want to suppress this
optimization when Zcb is present and the function is being optimized
for size.


On Mon, Sep 11, 2023 at 9:52 AM Jivan Hakobyan via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> In the case when we have C code like this
>
> int foo (int a) {
>    return 100 & ~a;
> }
>
> GCC generates the following instruction sequence
>
> foo:
>      not     a0,a0
>      andi    a0,a0,100
>      ret
>
> This patch replaces that with this sequence
> foo:
>      li a5,100
>      andn a0,a5,a0
>      ret
>
> The profitability comes from an out-of-order processor being able to
> issue the "li a5, 100" at any time after it's fetched while "not a0, a0" has
> to wait until any prior setter of a0 has reached completion.
>
>
> gcc/ChangeLog:
>         * config/riscv/bitmanip.md (*<optab>_not_const<mode>): New split
> pattern.
>
> gcc/testsuite/ChangeLog:
>         * gcc.target/riscv/zbb-andn-orn-01.c: New test.
>         * gcc.target/riscv/zbb-andn-orn-02.c: Likewise.
>
>
> --
> With the best regards
> Jivan Hakobyan

  reply	other threads:[~2023-09-11 19:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-11 16:43 Jivan Hakobyan
2023-09-11 19:16 ` Andrew Waterman [this message]
2023-09-12  0:56   ` Jeff Law

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='CA++6G0Do5=frLfEeG72a9ozmx6PVaqBtWcDquo7THEJHfHdxAQ@mail.gmail.com' \
    --to=andrew@sifive.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jivanhakobyan9@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).