struct u1 { float x; float y; }; float foo(struct u1 u) { return u.x + u.y; }
compiles into gcc-4.5 -O3 tgcc.c -c -o tgcc.o 0x0000000000000000 <+0>: movq %xmm0,-0x20(%rsp) 0x0000000000000006 <+6>: mov -0x20(%rsp),%rax 0x000000000000000b <+11>: mov %eax,-0x14(%rsp) 0x000000000000000f <+15>: shr $0x20,%rax 0x0000000000000013 <+19>: mov %eax,-0x10(%rsp) 0x0000000000000017 <+23>: movss -0x14(%rsp),%xmm0 0x000000000000001d <+29>: addss -0x10(%rsp),%xmm0 0x0000000000000023 <+35>: retq The instructions dealing with rax/eax can be elided if the movss and addss load from the correct stack locations. A better sequence, avoiding memory, might be pshufd %xmm0, %xmm1, 1 addss %xmm1, %xmm0 retq -- Summary: Struct with two floats generates poor code Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: svfuerst at gmail dot com GCC build triplet: x86_64-linux GCC host triplet: x86_64-linux GCC target triplet: x86_64-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43640