From: Jeff Law <jeffreyalaw@gmail.com>
To: Georg-Johann Lay <avr@gjlay.de>,
Roger Sayle <roger@nextmovesoftware.com>,
gcc-patches@gcc.gnu.org
Subject: Re: [middle-end PATCH] Prefer PLUS over IOR in RTL expansion of multi-word shifts/rotates.
Date: Fri, 19 Jan 2024 09:50:11 -0700 [thread overview]
Message-ID: <23b0bd81-fd43-4b44-91b4-871d681c11a3@gmail.com> (raw)
In-Reply-To: <71f8f116-e3b8-4e70-b30a-a4bc042466a2@gjlay.de>
On 1/19/24 09:05, Georg-Johann Lay wrote:
>
>
> Am 18.01.24 um 20:54 schrieb Roger Sayle:
>>
>> This patch tweaks RTL expansion of multi-word shifts and rotates to use
>> PLUS rather than IOR for disjunctive operations. During expansion of
>> these operations, the middle-end creates RTL like (X<<C1) | (Y>>C2)
>> where the constants C1 and C2 guarantee that bits don't overlap.
>> Hence the IOR can be performed by any any_or_plus operation, such as
>> IOR, XOR or PLUS; for word-size operations where carry chains aren't
>> an issue these should all be equally fast (single-cycle) instructions.
>> The benefit of this change is that targets with shift-and-add insns,
>> like x86's lea, can benefit from the LSHIFT-ADD form.
>>
>> An example of a backend that benefits is ARC, which is demonstrated
>> by these two simple functions:
>
> But there are also back-ends where this is bad.
>
> The reason is that with ORI, the back-end needs only to operate no
> these sub-words where the sub-mask is non-zero. But for PLUS this
> is not the case because the back-end does not know that intermediate
> carry will be zero. Hence, with PLUS, more instructions are needed.
> An example is AVR, but maybe much more target with multi-word operations
> are affected in a bad way.
>
> Take for example the case with 2 words and a value of 1.
>
> LO |= 1
> HI |= 0
>
> can be optimized to
>
> LO |= 1
>
> but for addition this is not the case:
>
> LO += 1
> HI +=c 0 ;; Does not know that always carry = 0.
I think it's clear that the decision is target and possibly uarch
specific within a target.
Which means that expmed is probably the right place and that we're going
to need to look for a good way for the target to control. I suspect
rtx_cost isn't likely a good fit.
Jeff
next prev parent reply other threads:[~2024-01-19 16:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-18 19:54 Roger Sayle
2024-01-19 11:03 ` Richard Biener
2024-01-19 13:26 ` Roger Sayle
2024-01-19 13:49 ` Richard Biener
2024-01-19 16:05 ` Georg-Johann Lay
2024-01-19 16:50 ` Jeff Law [this message]
2024-01-20 9:31 ` Uros Bizjak
2024-01-22 7:45 ` Richard Biener
2024-01-22 15:51 ` Jeff Law
2024-01-24 15:49 ` Georg-Johann Lay
2024-01-25 9:20 ` Richard Biener
2024-06-09 1:48 ` 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=23b0bd81-fd43-4b44-91b4-871d681c11a3@gmail.com \
--to=jeffreyalaw@gmail.com \
--cc=avr@gjlay.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=roger@nextmovesoftware.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).