Skip to content

[AVR] Induction variable not found (missed optimization) #151080

@tomtor

Description

@tomtor
void foo(int);
int ci[30];

void loopci()
{
  for (int i=0; i < sizeof(ci)/sizeof(ci[0]); i++)
    foo(ci[i]);
}

compiles to:

000000b4 <loopci>:
  b4:   ef 92           push    r14
  b6:   ff 92           push    r15
  b8:   0f 93           push    r16
  ba:   1f 93           push    r17
  bc:   00 e0           ldi     r16, 0x00       ; 0
  be:   10 e0           ldi     r17, 0x00       ; 0
  c0:   c8 01           movw    r24, r16
  c2:   7c 01           movw    r14, r24
  c4:   c8 01           movw    r24, r16
  c6:   88 0f           add     r24, r24
  c8:   99 1f           adc     r25, r25
  ca:   80 50           subi    r24, 0x00       ; 0
  cc:   98 4c           sbci    r25, 0xC8       ; 200
  ce:   fc 01           movw    r30, r24
  d0:   80 81           ld      r24, Z
  d2:   91 81           ldd     r25, Z+1        ; 0x01
  d4:   1a d0           rcall   .+52            ; 0x10a <foo>
  d6:   c7 01           movw    r24, r14
  d8:   01 96           adiw    r24, 0x01       ; 1
  da:   0d 31           cpi     r16, 0x1D       ; 29
  dc:   11 05           cpc     r17, r1
  de:   8c 01           movw    r16, r24
  e0:   80 f3           brcs    .-32            ; 0xc2 <.Lname26+0x3>
  e2:   1f 91           pop     r17
  e4:   0f 91           pop     r16
  e6:   ff 90           pop     r15
  e8:   ef 90           pop     r14
  ea:   08 95           ret

avr-gcc:

000000b4 <loopci>:
  b4:   cf 93           push    r28
  b6:   df 93           push    r29
  b8:   ca e1           ldi     r28, 0x1A       ; 26
  ba:   d8 e3           ldi     r29, 0x38       ; 56

000000bc <.L2>:
  bc:   89 91           ld      r24, Y+
  be:   99 91           ld      r25, Y+
  c0:   20 d0           rcall   .+64            ; 0x102 <foo>
  c2:   88 e3           ldi     r24, 0x38       ; 56
  c4:   c6 35           cpi     r28, 0x56       ; 86
  c6:   d8 07           cpc     r29, r24
  c8:   c9 f7           brne    .-14            ; 0xbc <.L2>
  ca:   df 91           pop     r29
  cc:   cf 91           pop     r28
  ce:   08 95           ret

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions