public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Maciej W. Rozycki" <macro@orcam.me.uk>
To: Andrew Pinski <pinskia@gmail.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>, gcc-patches@gcc.gnu.org
Subject: Re: RISC-V: Add divmod instruction support
Date: Sat, 18 Feb 2023 19:31:30 +0000 (GMT)	[thread overview]
Message-ID: <alpine.DEB.2.21.2302181848430.25434@angie.orcam.me.uk> (raw)
In-Reply-To: <CA+=Sn1m3TBcuPPLhy+EOyejAfKaK6SaD-8LeBqYdNCLzp_K2PA@mail.gmail.com>

On Sat, 18 Feb 2023, Andrew Pinski via Gcc-patches wrote:

> > > If we have division and remainder calculations with the same operands:
> > >
> > >   a = b / c;
> > >   d = b % c;
> > >
> > > We can replace the calculation of remainder with multiplication +
> > > subtraction, using the result from the previous division:
> > >
> > >   a = b / c;
> > >   d = a * c;
> > >   d = b - d;
> > >
> > > Which will be faster.
> >
> > Do you have any benchmarks that show that performance increase?  The ISA
> > manual specifically says the suggested sequence is div+mod, and while
> > those suggestions don't always pan out for real hardware it's likely
> > that at least some implementations will end up with the ISA-suggested
> > fusions.
> 
> I suspect I will be needing this kind of patch for the core that I am
> going to be using.
> If anything this should be under a tuning option.

 Barring the fusion case, which indeed asks for a dedicated `divmod' 
pattern (and then I suppose a post-reload splitter or a peephole so that 
where one of the two results produced has eventually turned out unused, we 
have means to discard the unneeded machine instruction), isn't the generic 
transformation something for the middle end to do based on RTX costs?

  Maciej

  parent reply	other threads:[~2023-02-18 19:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-17 14:02 Matevos Mehrabyan
2023-02-18 18:26 ` Palmer Dabbelt
2023-02-18 18:42   ` Andrew Pinski
2023-02-18 19:26     ` Palmer Dabbelt
2023-02-18 19:31     ` Maciej W. Rozycki [this message]
2023-02-18 20:57       ` Prathamesh Kulkarni
2023-02-18 21:07       ` Jeff Law
2023-02-19  1:14         ` Maciej W. Rozycki
2023-02-20  8:11           ` Richard Biener
2023-02-20 13:32             ` Alexander Monakov
2023-02-28 12:54               ` Maciej W. Rozycki
2023-02-18 21:06   ` Jeff Law
2023-02-18 21:30     ` Palmer Dabbelt
2023-02-18 21:57       ` Jeff Law
2023-02-20  1:27       ` Andrew Waterman
2023-04-28 20:09 ` 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=alpine.DEB.2.21.2302181848430.25434@angie.orcam.me.uk \
    --to=macro@orcam.me.uk \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=palmer@dabbelt.com \
    --cc=pinskia@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).