From: Segher Boessenkool <segher@kernel.crashing.org>
To: Jakub Jelinek <jakub@redhat.com>
Cc: Sudi Das <Sudi.Das@arm.com>,
"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
Marcus Shawcroft <Marcus.Shawcroft@arm.com>,
Richard Earnshaw <Richard.Earnshaw@arm.com>,
James Greenhalgh <James.Greenhalgh@arm.com>,
nd <nd@arm.com>
Subject: Re: [PATCH][GCC] Simplification of 1U << (31 - x)
Date: Wed, 12 Apr 2017 19:34:00 -0000 [thread overview]
Message-ID: <20170412193353.GJ4402@gate.crashing.org> (raw)
In-Reply-To: <20170412185934.GB1809@tucnak>
On Wed, Apr 12, 2017 at 08:59:34PM +0200, Jakub Jelinek wrote:
> On Wed, Apr 12, 2017 at 01:15:56PM -0500, Segher Boessenkool wrote:
> > On Wed, Apr 12, 2017 at 07:06:38PM +0200, Jakub Jelinek wrote:
> > > On Wed, Apr 12, 2017 at 09:29:55AM +0000, Sudi Das wrote:
> > > > This is a fix for PR 80131
> > > > Currently the code A << (B - C) is not simplified.
> > > > However at least a more specific case of 1U << (C -x) where C = precision(type) - 1 can be simplified to (1 << C) >> x.
> > >
> > > Is that always a win though?
> > > Some constants have higher costs than others on various targets, some
> > > significantly higher. This change might be beneficial only
> > > if if C is as expensive as 1, then you get rid of a one (typically cheap)
> > > operation.
> > > Which makes me wonder whether this should be done at GIMPLE time and not
> > > at RTL time (expansion or combine etc.) when one can compare the RTX costs.
> >
> > Yeah, either combine or simplify-rtx I'd say.
> >
> > The transform A << (B - C) ---> (A << B) >> C
> > only works if A << B does not overflow but A << (B + 1) does (and then
>
> Is that really true? The A << B does not overflow is obvious precondition.
>
> But consider say A 5U, B 29 and C (not compile time known) -2.
Ah yes, A unsigned. Bah.
> 5U << 31 is valid 0x80000000U, but (5U << 29) >> (-2) is UB.
> Isn't the other condition instead that either C must be non-negative, or
> B must be number of bits in A's type - 1, i.e. that for negative C
> A << (B - C) would already be always UB?
> But then unless we know C is non-negative, A must be really just 1,
> otherwise A << B overflows.
Yeah.
Segher
next prev parent reply other threads:[~2017-04-12 19:34 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-12 9:30 Sudi Das
2017-04-12 17:06 ` Jakub Jelinek
2017-04-12 18:16 ` Segher Boessenkool
2017-04-12 18:59 ` Jakub Jelinek
2017-04-12 19:34 ` Segher Boessenkool [this message]
2017-04-13 11:16 Wilco Dijkstra
2017-04-13 11:21 ` Jakub Jelinek
2017-04-13 11:33 ` Wilco Dijkstra
2017-04-13 11:41 ` Jakub Jelinek
2017-04-13 11:49 ` Richard Biener
2017-04-13 11:55 ` Jakub Jelinek
2017-04-13 12:01 ` Wilco Dijkstra
2017-08-01 9:15 ` Sudi Das
2017-08-04 10:16 ` Richard Biener
2017-09-26 12:44 ` Sudi Das
2017-09-26 13:06 ` Jakub Jelinek
2017-09-26 13:20 ` Wilco Dijkstra
2017-10-06 17:00 ` Sudi Das
2017-10-09 12:05 ` Richard Biener
2017-10-09 13:04 ` Wilco Dijkstra
2017-10-10 11:12 ` Sudi Das
2017-11-07 12:37 ` Wilco Dijkstra
2017-11-07 14:48 ` Christophe Lyon
2017-11-07 14:49 ` Wilco Dijkstra
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=20170412193353.GJ4402@gate.crashing.org \
--to=segher@kernel.crashing.org \
--cc=James.Greenhalgh@arm.com \
--cc=Marcus.Shawcroft@arm.com \
--cc=Richard.Earnshaw@arm.com \
--cc=Sudi.Das@arm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=nd@arm.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).