This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] Fix pr14796
- From: Paul Brook <paul at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: James A. Morrison <ja2morri at csclub dot uwaterloo dot ca>
- Date: Thu, 9 Jun 2005 15:29:15 +0100
- Subject: Re: [patch] Fix pr14796
- References: <kfh7jh364hw.fsf@csclub.uwaterloo.ca>
On Thursday 09 June 2005 14:31, James A. Morrison wrote:
> Hi,
>
> This patch adds some transformations for shifts and rotates such as
> (a << c1) << c2 to a << (c1+c2). This patch has been bootstrapped and
> regtested on ia64-linux with no new regressions. Ok for mainline?
+ /* Transform (x >> c1) << c2... */
+ /* ...into (x >> (c1 - c2)) & (-1<<c2). */
+ /* ...into (x & (-1<<c1)) << (c2 - c1). */
Is this a good idea?
There are certainly some targets (eg. Arm) where shifts tend to be cheaper
than masks because the mask can require a constant load, and the shift can be
combined with subsequent instructions.
Even on i386 the latter can generate larger code.
typedef unsigned int ui;
ui foo(ui a)
{
return (a & 0xffffc000) << 4;
}
ui bar(ui a)
{
return (a >> 14) << 18;
}
Arm:
foo:
bic r0, r0, #16320
bic r0, r0, #63
mov r0, r0, asl #4
bx lr
bar:
mov r0, r0, lsr #14
mov r0, r0, asl #18
bx lr
i386:
# 13 bytes
foo:
movl 4(%esp), %eax
andl $-16384, %eax
sall $4, %eax
ret
# 10 bytes
bar:
movl 4(%esp), %eax
shrl $14, %eax
sall $18, %eax
ret
Paul