This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Fix pr14796


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]