From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27395 invoked by alias); 9 Jul 2011 09:36:38 -0000 Received: (qmail 27193 invoked by uid 22791); 9 Jul 2011 09:36:37 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_LQ,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; Sat, 09 Jul 2011 09:36:24 +0000 From: "gjl at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/49687] New: AVR: Missed optimization for widening MUL X-Bugzilla-Reason: CC X-Bugzilla-Type: new 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: 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: Sat, 09 Jul 2011 09:36: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-07/txt/msg00680.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49687 Summary: AVR: Missed optimization for widening MUL Product: gcc Version: 4.6.1 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: target AssignedTo: unassigned@gcc.gnu.org ReportedBy: gjl@gcc.gnu.org Target: avr With avr-gcc 4.6.1 and -Os -mmcu=atmega88 -S -dp int mul8_55 (char x) { return x * 55; } gets compiled to mul8_55: ldi r25,lo8(55) ; 7 *movqi/2 [length = 1] muls r24,r25 ; 8 mulqihi3 [length = 3] movw r24,r0 clr r1 ret ; 26 return [length = 1] which is fine. If the constant is 126, however, the result is bloated and might be related to PR36467, i.e. MUL* is better than shift. mul8_126: clr r25 ; 7 extendqihi2/1 [length = 3] sbrc r24,7 com r25 movw r18,r24 ; 28 *movhi/1 [length = 1] lsl r18 ; 33 *ashlhi3_const/2 [length = 2] rol r19 lsr r25 ; 34 *ashlhi3_const/5 [length = 5] mov r25,r24 clr r24 ror r25 ror r24 sub r24,r18 ; 12 subhi3/1 [length = 2] sbc r25,r19 ret ; 31 return [length = 1] If the constant is 155, a MUL is invented, but a widening MUL would be smarter: mul8_155: mov r20,r24 ; 6 extendqihi2/2 [length = 4] clr r21 sbrc r20,7 com r21 ldi r18,lo8(155) ; 7 *movhi/4 [length = 2] ldi r19,hi8(155) mul r20,r18 ; 8 *mulhi3_enh [length = 7] movw r24,r0 mul r20,r19 add r25,r0 mul r21,r18 add r25,r0 clr r1 ret ; 26 return [length = 1]