From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2145 invoked by alias); 2 Mar 2011 05:30:56 -0000 Received: (qmail 2135 invoked by uid 22791); 2 Mar 2011 05:30:54 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 02 Mar 2011 05:30:50 +0000 From: "svfuerst at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/47949] New: Missed optimization for -Os using xchg instead of mov. X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: svfuerst at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Wed, 02 Mar 2011 05:30:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-03/txt/msg00143.txt.bz2 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.