------- Comment #16 from rask at gcc dot gnu dot org  2007-09-16 13:38 -------
Created an attachment (id=14211)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=14211&action=view)
quick and dirty patch to reduce code size

A fundamental problem with the AVR back end is that it sabotages the RTL
optimizer's attempts to optimize away redundant move insns. With this patch, I
get better code (-O2):

foo:
        push r29         ;  73  *pushhi/1       [length = 2]
        push r28
        rcall .  ;  79  *addhi3_sp_R_pc2        [length = 3]
        rcall .
        rcall .
        in r28,__SP_L__  ;  90  *movqi/6        [length = 1]
        in r29,__SP_H__  ;  91  *movqi/6        [length = 1]
/* prologue: function */
/* frame size = 6 */
        ldi r24,lo8(2)   ;  68  *movqi/2        [length = 1]
        std Y+5,r24      ;  70  *movqi/3        [length = 1]
        std Y+6,__zero_reg__     ;  71  *movqi/3        [length = 1]
        ldi r22,lo8(2)   ;  21  *movqi/2        [length = 1]
        ldi r23,lo8(0)   ;  23  *movqi/2        [length = 1]
        ldi r18,lo8(1)   ;  42  *movqi/2        [length = 1]
        ldi r19,lo8(0)   ;  43  *movqi/2        [length = 1]
        ldi r20,lo8(0)   ;  44  *movqi/2        [length = 1]
        ldi r21,lo8(0)   ;  45  *movqi/2        [length = 1]
        ldi r24,lo8(0)   ;  48  *movqi/2        [length = 1]
        ldi r25,lo8(0)   ;  49  *movqi/2        [length = 1]
/* epilogue start */
        adiw r28,6       ;  85  *addhi3/2       [length = 1]
        out __SP_L__,r28         ;  92  *movqi/5        [length = 1]
        out __SP_H__,r29         ;  93  *movqi/5        [length = 1]
        pop r28  ;  87  pophi   [length = 2]
        pop r29
        ret      ;  88  return_from_epilogue    [length = 1]
        .size   foo, .-foo
/* File "/home/rask/pr11180.c": code    0 = 0x0000 (   0), prologues   0,
epilogues   0 */

Perhaps a peephole optimization could replace insns 48 and 49 with "movw
r25:r24, r21:r20".
The only big further improvement I see would be to get rid of the stack var.


-- 


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

Reply via email to