http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49127
Summary: -Os generates constant mov instead of instruction xor and mov when zeroing Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: rtl-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: msha...@users.sourceforge.net void zero (void* p) { *reinterpret_cast<ulong*>(p) = 0; } Generates: 48 c7 07 00 00 00 00 movq $0x0,(%rdi) This is shorter by 2 bytes: 31 c0 xor %eax,%eax 48 89 07 mov %rax,(%rdi) And can be reused in further assignments of zero for more savings: 31 c0 xor %eax,%eax 48 89 07 mov %rax,(%rdi) 48 89 47 04 mov %rax,0x4(%rdi)