http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47949
Summary: Missed optimization for -Os using xchg instead of mov.
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: target
AssignedTo: [email protected]
ReportedBy: [email protected]
Target: x86 / amd64
xchg %eax, reg is a one-byte instruction. If reg is dead, this instruction
could replace the two-byte mov reg, %eax for a one-byte savings.
ie:
int foo(int x)
{
return x;
}
currently compiles to
mov %edi,%eax
retq
with -Os, whereas the following may be better:
xchg %eax, %edi
retq
(Similar cases exist with mov reg, %rax; mov reg, %ax; and mov reg, %al)
Note that xchg is slower than mov, so this is only an optimization when size is
more important than speed.