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: Jakub Jelinek <jakub at redhat dot com>
- To: Richard Biener <richard dot guenther at gmail dot com>, Uros Bizjak <ubizjak at gmail dot com>
- Cc: Wilco Dijkstra <Wilco dot Dijkstra at arm dot com>, Sudi Das <Sudi dot Das at arm dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, nd <nd at arm dot com>, Richard Earnshaw <Richard dot Earnshaw at arm dot com>, James Greenhalgh <James dot Greenhalgh at arm dot com>
- Date: Thu, 13 Apr 2017 13:55:00 +0200
- Subject: Re: [PATCH][GCC] Simplification of 1U << (31 - x)
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jakub at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6B90114BFCA
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6B90114BFCA
- References: <AM5PR0802MB2610B3E04DF2484B04208CEC83020@AM5PR0802MB2610.eurprd08.prod.outlook.com> <20170413112151.GD1809@tucnak> <AM5PR0802MB2610B75CC3BDBA5C021B3DA083020@AM5PR0802MB2610.eurprd08.prod.outlook.com> <20170413114125.GE1809@tucnak> <CAFiYyc1Jk2hpuw1xnGD98SNQzzQHTzaoxFhq5C0ZeJVvZ2hODw@mail.gmail.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Thu, Apr 13, 2017 at 01:49:01PM +0200, Richard Biener wrote:
> It is IMHO a valid GIMPLE optimization / canonicalization.
As I said, we can do it as GIMPLE canonicalization, but
we should have code to undo it if beneficial at RTL level.
And the patch has not included that.
>
> movabsq $-9223372036854775808, %rax
>
> so this should then have been generated as 1<<63?
Maybe. But it seems to be still more expensive than the original code,
though better than movabsq:
__attribute__((noinline, noclone)) unsigned long long int
foo (int x)
{
asm volatile ("" : : : "memory");
return 1ULL << (63 - x);
}
__attribute__((noinline, noclone)) unsigned long long int
bar (int x)
{
asm volatile ("" : : : "memory");
return (1ULL << 63) >> x;
}
__attribute__((noinline, noclone)) unsigned long long int
baz (int x)
{
unsigned long long int y = 1;
asm volatile ("" : "+r" (y) : : "memory");
return (y << 63) >> x;
}
int
main (int argc, const char **argv)
{
int i;
if (argc == 1)
for (i = 0; i < 1000000000; i++)
asm volatile ("" : : "r" (foo (13)));
else if (argc == 2)
for (i = 0; i < 1000000000; i++)
asm volatile ("" : : "r" (bar (13)));
else if (argc == 3)
for (i = 0; i < 1000000000; i++)
asm volatile ("" : : "r" (baz (13)));
return 0;
}
Jakub