This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH][GCC] Simplification of 1U << (31 - x)
- From: Segher Boessenkool <segher at kernel dot crashing dot org>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: Sudi Das <Sudi dot Das at arm dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, Marcus Shawcroft <Marcus dot Shawcroft at arm dot com>, Richard Earnshaw <Richard dot Earnshaw at arm dot com>, James Greenhalgh <James dot Greenhalgh at arm dot com>, nd <nd at arm dot com>
- Date: Wed, 12 Apr 2017 13:15:56 -0500
- Subject: Re: [PATCH][GCC] Simplification of 1U << (31 - x)
- Authentication-results: sourceware.org; auth=none
- References: <VI1PR08MB26887B0900BF829A25462F0698000@VI1PR08MB2688.eurprd08.prod.outlook.com> <20170412170638.GA1809@tucnak>
Hi,
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
always does work afaics). Or if we know C is non-negative and A << B
does not overflow. So realistically A and B need to be constant.
> 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).
The inverse transform only works for A=1, not for the more general case.
Segher