public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
To: Jakub Jelinek <jakub@redhat.com>, Sudi Das <Sudi.Das@arm.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>, nd <nd@arm.com>,
	Richard Earnshaw	<Richard.Earnshaw@arm.com>,
	James Greenhalgh <James.Greenhalgh@arm.com>
Subject: Re: [PATCH][GCC] Simplification of 1U << (31 - x)
Date: Thu, 13 Apr 2017 11:16:00 -0000	[thread overview]
Message-ID: <AM5PR0802MB2610B3E04DF2484B04208CEC83020@AM5PR0802MB2610.eurprd08.prod.outlook.com> (raw)

>On Wed, Apr 12, 2017 at 09:29:55AM +0000, Sudi Das wrote:
> > Hi all
> > 
> > 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?

Yes assuming left and right shift have the same performance.

> 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.

Most targets can create the constant cheaply. Targets that can't would need 2
instructions (move+shift) or a literal load. That's not worse compared to the
original sequence (3 operations). The constant can be shared or lifted out of
a loop, so we're saving 1 subtract per use of the sequence.

> 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.
> Or do this at match.pd as canonicalization and then have RTL transformation
> to rewrite such (1U << C) >> X as 1U << (C - X) if the latter is faster (or
> shorter).

I can't see why that would be useful for just this pattern. There are lots more useful
cases where GCC should simplify immediates to fit the target but it doesn't currently.
For example it changes x < 0x100000 to x <= 0xfffff which is worse on many targets.

Wilco

             reply	other threads:[~2017-04-13 11:16 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-13 11:16 Wilco Dijkstra [this message]
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
  -- strict thread matches above, loose matches on Subject: below --
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

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=AM5PR0802MB2610B3E04DF2484B04208CEC83020@AM5PR0802MB2610.eurprd08.prod.outlook.com \
    --to=wilco.dijkstra@arm.com \
    --cc=James.Greenhalgh@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).