This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug target/47949] New: Missed optimization for -Os using xchg instead of mov.


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]