public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/54816] New: [avr] shift is better than widening mul
@ 2012-10-04 18:28 gjl at gcc dot gnu.org
  2023-04-11  5:22 ` [Bug target/54816] " klaus.doldinger64 at googlemail dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: gjl at gcc dot gnu.org @ 2012-10-04 18:28 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54816

             Bug #: 54816
           Summary: [avr] shift is better than widening mul
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: gjl@gcc.gnu.org
                CC: eric.weddington@atmel.com
            Target: avr


The following C test case 

int wmul (char a, char b)
{
    return a * (char) (b << 3);
}

$ avr-gcc wmul.c -S -Os -mmcu=atmega8 -dp

produces with current avr-gcc:


wmul:
    ldi r25,lo8(8)     ;  25    movqi_insn/2    [length = 1]
    muls r22,r25     ;  26    mulqihi3    [length = 3]
    movw r22,r0
    clr __zero_reg__
    muls r24,r22     ;  17    mulqihi3    [length = 3]
    movw r24,r0
    clr __zero_reg__
    ret     ;  29    return    [length = 1]
    .ident    "GCC: (GNU) 4.8.0 20121004 (experimental)"


avr-gcc-4.7 was smarter with its code:

wmul:
    lsl r22     ;  10    *ashlqi3/5    [length = 3]
    lsl r22
    lsl r22
    muls r24,r22     ;  12    mulqihi3    [length = 3]
    movw r22,r0
    clr __zero_reg__
    movw r24,r22     ;  31    *movhi/1    [length = 1]
    ret     ;  30    return    [length = 1]
    .ident    "GCC: (GNU) 4.7.2"


The 4.7 code is faster, smaller and has smaller register pressure.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-04-22 20:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-04 18:28 [Bug target/54816] New: [avr] shift is better than widening mul gjl at gcc dot gnu.org
2023-04-11  5:22 ` [Bug target/54816] " klaus.doldinger64 at googlemail dot com
2023-04-15 13:27 ` roger at nextmovesoftware dot com
2023-04-15 15:48 ` klaus.doldinger64 at googlemail dot com
2023-04-16 12:04 ` cvs-commit at gcc dot gnu.org
2023-04-16 12:11 ` roger at nextmovesoftware dot com
2023-04-21 20:09 ` gjl at gcc dot gnu.org
2023-04-22 20:02 ` cvs-commit at gcc dot gnu.org

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).