public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <jeffreyalaw@gmail.com>
To: Richard Biener <richard.guenther@gmail.com>,
	Georg-Johann Lay <avr@gjlay.de>
Cc: 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: Mon, 22 Jan 2024 08:51:55 -0700	[thread overview]
Message-ID: <1c9ed2d2-70b9-42c5-8a14-ffc074913d00@gmail.com> (raw)
In-Reply-To: <CAFiYyc2+GN8k+bqu4qPbMNTYime0QQ=EG0c3w+3Xz9bF31aT8w@mail.gmail.com>



On 1/22/24 00:45, Richard Biener wrote:
> On Fri, Jan 19, 2024 at 5:06 PM Georg-Johann Lay <avr@gjlay.de> 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 wonder if the PLUS can be done on the lowpart only to make this
> detail obvious?
In theory, yes.   This class of problems has often been punted to the 
target expanders (far from ideal).

I still suspect the way forward here is to have the exp* code query one 
or more target properties to guide IOR vs PLUS selection.

Jeff


  reply	other threads:[~2024-01-22 15:51 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
2024-01-20  9:31     ` Uros Bizjak
2024-01-22  7:45   ` Richard Biener
2024-01-22 15:51     ` Jeff Law [this message]
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=1c9ed2d2-70b9-42c5-8a14-ffc074913d00@gmail.com \
    --to=jeffreyalaw@gmail.com \
    --cc=avr@gjlay.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.com \
    --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).