Why does avr-gcc delete my empty "for" loops if I compile with
optimization on?
I am able to preserve the loop if I add a NOP in the loop but that will
eat up one clock cycle. Is there a way to preserve the empty loops
without adding any NOP clock cycles? Is this a bug? Below is a test C
code and the avr-gcc generated asm:
///////////* C code /////////////*/
int main(void)
{ int counton, countoff;
int tempcount;
do
{
counton = 27; countoff=1700; //should div by 23
for(tempcount = 0; tempcount < counton; tempcount++)
{ ;
}
for(tempcount = 0; tempcount < countoff; tempcount++)
{;
}
}
while(1);
return 0;
}
///////* ASM code /////////////*/
main:
/* prologue: frame size=0 */
ldi r28,lo8(__stack - 0)
ldi r29,hi8(__stack - 0)
out __SP_H__,r29
out __SP_L__,r28
/* prologue end (size=4) */
ldi r24,lo8(0)
ldi r25,hi8(0)
rjmp .L12
.L4:
adiw r24,1
.L12:
cpi r24,27
cpc r25,__zero_reg__
brlt .L4
ldi r24,lo8(0)
ldi r25,hi8(0)
rjmp .L12
/* epilogue: frame size=0 */
_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list