From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3052 invoked by alias); 4 Sep 2011 22:20:15 -0000 Received: (qmail 3043 invoked by uid 22791); 4 Sep 2011 22:20:13 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_GJ,TW_OV 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; Sun, 04 Sep 2011 22:19:59 +0000 From: "gjl at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/50256] AVR GCC - several unnecessary register moves Date: Sun, 04 Sep 2011 22:20:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: gjl at gcc dot gnu.org X-Bugzilla-Status: WAITING X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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-09/txt/msg00278.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50256 --- Comment #6 from Georg-Johann Lay 2011-09-04 22:19:53 UTC --- You don't need R20: Simply use %D0 which is cleared, anyway. As %0 is early clobber, it's not an input and you can clear is at the beginning. You don't need to clear R4/R5 (similar R6/R7): Just rearrange multiplications and use (note R6 is (implicitely) 0 at that time) mul %A1,%C2 movw r4,r0 instead of mul %A1,%C2 add r4,r0 adc r5,r1 You don't need to move to answer by hand; just use %A0 instead of R5 etc. and you save moves and register footprint (notice that this interferes with previous hint because you change registers even/odd; it's up to you to work it out and find smartest way of your assembler). Finally, you could let the compiler allocate temporary registers for you, i.e. a 16-bit instead of R2/R3 etc. The compiler knows better which registers are best and will try to use call-clobbered registers instead of expensive call-used ones. All in all, you will get a much greater performance gain by tweaking you code than the compiler could ever do by saving some poor register moves ;-)