<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/151080>151080</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[AVR] Induction variable not found (missed optimization)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tomtor
</td>
</tr>
</table>
<pre>
```
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
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVk2P4jgQ_TXmUmrklOPgHHKAYZBW2tMeVtq5ObbT7VXAKAlM7_z6lT9CDA2H3QjNSKn3yq5XVa8jx9G-n4xpCN8Rvl_Jy_ThhmZyx8kNq9bpfxpS0fSj26uzGjrnCAp7mgjWhO0I3drTBMoSvmOU8H18N6N7587KEhQeTbdk44MAnRsgZgFL2J4StgMLhH2D0f4yriMoPKsmeMhf8F04IRwMluAu_HzidK2AsTdMOHHv_82qIHSr3PFsezPC5Ajbxnc5hIanLf2NUgXse0QCtCVhWwAwHdQI58v4AQAwFGWMVjHahejyLDgecSLiaAc1y6JVjMoYLUL0WZZNxKmUhYKh0GsLcxb8BvST0sTzetHIMClzYCzPwt3cuAtL0chSAmiRsY7u-jOwsPSs-foKI3yjnsC9Uh6LUTBV_rfUSV8hvHRSa8hBc84kbl17BZdHapXgPMJjL1RSW1DgFMZLa7OcT1VUSfdaQKmyA8ZW2ewA-vlNBBbSxEvqd8-E8TxG8zo0vV1MFNDHWueL_YiQJHVdeEjeT52X-oPg7hYOdXzSIiYI-hcSdD4Og5J9DwBrgjuez3EiF1T65fBbx77HPKkxauNL-9K9VNA89QXU1V1j7M97zYvsuHBRnZpENbC8UHV-GPpin1GjOYBO_SoKoBzUWeWzPiQhUm_Eq97EA-bemKU3HYN2UKMHrd_YE7UUerHWv5_k0WBFcEc_2aybwWXVCzi78-1qIVouNpFfasHFtTCZ7dAH3Gw5RizG9YiBzMLMrLSAmsNgpq8GKq_D23tYgv9pnuqZsQ0o7jxUv3K_1NXZQ5UEcz_7NuSK47DNx-HeXrUAwx6I8wGBzERG5lUsNhWoYk8xry6Nmajvu_WwuX_5P1u5GdcBv6D4HWo2X6Svd7Qqv05dQfFh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