http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57302
Bug ID: 57302 Summary: Should merge zeroing multiple consecutive memory locations Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: msharov at users dot sourceforge.net struct A { short a,b; A (void); }; A::A (void) : a(0),b(0) {} void MoveA (const A* a, A* b) { *b = *a; } Generates: _ZN1AC2Ev: movw $0, (%rdi) movw $0, 2(%rdi) ret _Z5MoveAPK1APS_: movl (%rdi), %eax movl %eax, (%rsi) ret The optimizer can see that a and b are consecutive in memory and can merge the memory movs into a single 4-byte mov, but does not do the same for the zeroing code in the constructor. Merging the zeroing to movl, movq, and mov[au]ps (when SSE is available), would produce smaller code and fewer memory accesses.