From: Jeff Law <jeffreyalaw@gmail.com>
To: "Maciej W. Rozycki" <macro@orcam.me.uk>,
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 14:07:59 -0700 [thread overview]
Message-ID: <26ca669c-70ce-e475-717e-3c36f1e1c703@gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.21.2302181848430.25434@angie.orcam.me.uk>
On 2/18/23 12:31, Maciej W. Rozycki wrote:
> 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?
I originally though the same way you did Maciej.
The problem is you don't see it as a divmod in expand_divmod unless you
expose a divmod optab. See tree-ssa-mathopts.cc's divmod handling.
jeff
next prev parent reply other threads:[~2023-02-18 21:08 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
2023-02-18 20:57 ` Prathamesh Kulkarni
2023-02-18 21:07 ` Jeff Law [this message]
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=26ca669c-70ce-e475-717e-3c36f1e1c703@gmail.com \
--to=jeffreyalaw@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=macro@orcam.me.uk \
--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).