public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "gjl at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/49687] New: AVR: Missed optimization for widening MUL
Date: Sat, 09 Jul 2011 09:36:00 -0000	[thread overview]
Message-ID: <bug-49687-4@http.gcc.gnu.org/bugzilla/> (raw)

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]


             reply	other threads:[~2011-07-09  9:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-09  9:36 gjl at gcc dot gnu.org [this message]
2011-07-09  9:37 ` [Bug target/49687] " gjl at gcc dot gnu.org
2011-07-09  9:39 ` gjl at gcc dot gnu.org
2011-07-14 18:43 ` eric.weddington at atmel dot com
2011-07-14 18:45 ` [Bug target/49687] [4.6 Regression][avr] " eric.weddington at atmel dot com
2011-07-20 17:25 ` gjl at gcc dot gnu.org
2011-07-28  8:03 ` gjl at gcc dot gnu.org
2011-07-29 11:28 ` gjl at gcc dot gnu.org
2011-07-29 11:50 ` gjl at gcc dot gnu.org
2011-08-11  7:51 ` gjl at gcc dot gnu.org
2011-08-11 21:45 ` gjl at gcc dot gnu.org
2011-09-09 18:09 ` gjl at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-49687-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).