This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/50883] [ARM] Suboptimal optimization for small structures
- From: "sebastian dot huber at embedded-brains dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 27 Oct 2011 15:19:57 +0000
- Subject: [Bug target/50883] [ARM] Suboptimal optimization for small structures
- Auto-submitted: auto-generated
- References: <bug-50883-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50883
--- Comment #5 from Sebastian Huber <sebastian.huber@embedded-brains.de> 2011-10-27 15:19:57 UTC ---
If we look at the function f (the function g is similar):
struct s {
int alignment;
unsigned char a;
unsigned char b;
unsigned char c;
unsigned char d;
};
unsigned f(struct s x)
{
return x.a | (x.b << 8) | (x.c << 16) | (x.d << 24);
}
Currently ARM GCC produces this:
f:
sub sp, sp, #8
add r3, sp, #8
stmdb r3, {r0, r1}
ldrb r0, [sp, #6]
ldrb r3, [sp, #5]
lsls r0, r0, #16
ldrb r2, [sp, #4]
orr r0, r0, r3, lsl #8
ldrb r3, [sp, #7]
orrs r0, r0, r2
orr r0, r0, r3, lsl #24
add sp, sp, #8
bx lr
According to the ARM EABI, this structure is passed in registers r0 and r1.
The return value is in r0. This function may be reduced to:
f:
mov r0, r1
bx lr
The PowerPC GCC performs this optimization.