This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/47949] New: Missed optimization for -Os using xchg instead of mov.
- From: "svfuerst at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 2 Mar 2011 05:30:49 +0000
- Subject: [Bug target/47949] New: Missed optimization for -Os using xchg instead of mov.
- Auto-submitted: auto-generated
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: unassigned@gcc.gnu.org
ReportedBy: svfuerst@gmail.com
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.