[patch, CSE] Bit-field insertion optimization
Andrew Stubbs
ams@codesourcery.com
Thu Dec 9 16:58:00 GMT 2010
The attached patch fixes a bug in which constant assignments to bit
fields are improperly optimized. I'm seeing this on ARM, but I imagine
it affects other targets similarly.
The first problem is that CSE cannot determine that the result is
constant because the auto-variable is implicitly initialized. I have
solved this by moving up the init-regs pass to before cse2. It might be
better to move it before cse1, but that's a bigger change, so I wasn't sure?
The second problem is that the pattern match for ZERO_EXTRACT requires
that the operand is an immediate constant, which is never the case on
ARM (and presumably is only the case with a limited range of inputs even
on other targets). I have added code to detect known-constant input
registers.
Test case:
struct bits
{
unsigned a:5;
unsigned b:5;
unsigned c:5;
unsigned d:5;
};
struct bits
f (unsigned int a)
{
struct bits bits = {0,0,0,0};
bits.a = 1;
bits.b = 2;
bits.c = 3;
bits.d = a;
return bits;
}
Before, compiled for ARM with "-O2 -mcpu=cortex-a8 -mthumb":
movs r2, #1
movs r3, #0
bfi r3, r2, #0, #5
movs r2, #2
bfi r3, r2, #5, #5
movs r2, #3
bfi r3, r2, #10, #5
bfi r3, r0, #15, #5
mov r0, r3
bx lr
After:
movw r3, #3137
bfi r3, r0, #15, #5
mov r0, r3
bx lr
OK for commit, once stage 1 opens again?
Andrew
-------------- next part --------------
A non-text attachment was scrubbed...
Name: arm-zero-extract-cse.patch
Type: text/x-patch
Size: 2825 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20101209/b9457b8b/attachment.bin>
More information about the Gcc-patches
mailing list