public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jim Wilson <jimw@sifive.com>
To: Andrew Waterman <andrew@sifive.com>
Cc: Levy Hsu <admin@levyhsu.com>,
	GCC Patches <gcc-patches@gcc.gnu.org>,
	 Kito Cheng <kito.cheng@gmail.com>
Subject: Re: [PATCH] [RISCV] Add Pattern for builtin overflow
Date: Wed, 28 Apr 2021 13:18:25 -0700	[thread overview]
Message-ID: <CAFyWVabpJhGsRF01EiFAkQNzYPq=Y99imhQvprYmVsU0H=whEA@mail.gmail.com> (raw)
In-Reply-To: <CA++6G0C8xJjMnGPW9duUTXFsyfaBYcjVDssfgC76NkiHYv3gmQ@mail.gmail.com>

On Tue, Apr 27, 2021 at 12:45 AM Andrew Waterman <andrew@sifive.com> wrote:

> > signed addition (SImode with RV64):
> >         add     t0, t1, t2
> >     sext.w  t3, t0
> >     bne     t0, t3, overflow
>
> The following version has the same instruction count but offers more ILP:
>
>   add t0, t1, t2
>   addw t3, t1, t2
>   bne t0, t3, overflow
>

This is a good suggestion, but in the interests of making forward progress
here, I'd like to accept the patch and then file these as bugzillas as ways
to further improve the patch.

> > unsigned addition (SImode with RV64):
> >     sext.w  t3, t1
> >     addw        t0, t1, t2
> >     bltu        t0, t3, overflow
>
> I think you can do this in two instructions, similar to the previous
> pattern:
>
>   addw t0, t1, t2
>   bltu t0, t1, overflow
>

Likewise.

> > signed subtraction (SImode with RV64):
> >         sub     t0, t1, t2
> >     sext.w  t3, t0
> >     bne     t0, t3, overflow
>
> See analogous addition comment.
>

Likewise.

>
> > unsigned subtraction (SImode with RV64):
> >     sext.w  t3, t1
> >     subw        t0, t1, t2
> >     bltu    t0, t3, overflow
>
> See analogous addition comment.
>

Likewise.

> > unsigned multiplication (SImode with RV64):
> >     slli    t0,t0,32
> >         slli    t1,t1,32
> >         srli    t0,t0,32
> >         srli    t1,t1,32
> >         mul         t0,t0,t1
> >         srai    t5,t0,32
> >         bne         t5, 0, overflow
>
> I think you can eliminate the first two right shifts by replacing mul
> with mulhu... something like:
>
>   slli rx, rx, 32
>   slli ry, ry, 32
>   mulhu rz, rx, ry
>   srli rt, rz, 32
>   bnez rt, overflow
>

Likewise, except this should be a separate bugzilla.

Jim

  reply	other threads:[~2021-04-28 20:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-27  6:08 Levy Hsu
2021-04-27  7:45 ` Andrew Waterman
2021-04-28 20:18   ` Jim Wilson [this message]
2021-04-28 23:04     ` Andrew Waterman
2021-04-29 22:02       ` Jim Wilson
2021-05-02  0:06         ` Andrew Waterman
2021-04-29  5:42 Levy Hsu
2021-04-30  0:59 ` Jim Wilson

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='CAFyWVabpJhGsRF01EiFAkQNzYPq=Y99imhQvprYmVsU0H=whEA@mail.gmail.com' \
    --to=jimw@sifive.com \
    --cc=admin@levyhsu.com \
    --cc=andrew@sifive.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=kito.cheng@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).