https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115828

--- Comment #2 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> Turning off ivopts `-fno-ivopts`. avr gives:
> .L2:
>         sts v+1,r19
>         sts v,r18
>         subi r18,2
>         sbc r19,__zero_reg__
>         sbiw r24, 1
>         brne .L2
> 
> Which seems like reasonable code.

Not really, it is using TWO counters: One that starts at 19 and decrements by
one, PLUS one that starts at 36 and decrements by 2.

Though with -fno-tree-loop-optimize -Os it is only using one counter.  (Insn 32
is sub-optimal due to target issue PR115830, but apart from that you cannot do
better):

loop:
    ldi r24,lo8(36)      ;  26  [c=4 l=2]  *movhi/4
    ldi r25,0   
.L2:
    sts v+1,r25  ;  22  [c=4 l=4]  *movhi/3
    sts v,r24
    sbiw r24,2   ;  23  [c=4 l=1]  *addhi3_clobber/0
    sbrs r25,7   ;  32  [c=4 l=2]  *sbrx_branchhi
    rjmp .L2    
/* epilogue start */
    ret          ;  29  [c=0 l=1]  return

Reply via email to