Attached code file is compiled.
Here is the critical passage:
inline void taskSignal(void)
{
unsigned char i;
PORTB |= _BV(PB4);
PORTB |= _BV(PB5);
PORTB |= _BV(PB6);
i=0;
do
{
i+=2;
}
while( i<245 );
i=0;
do
{
i+=3;
}
while( i<245 );
PORTB &= ~_BV(PB4);
i=pos1;
do
{
i+=1;
}
while( i<245 );
PORTB &= ~_BV(PB5);
PORTB &= ~_BV(PB6);
}
When compiling without optimization I get:
do
{
i+=2;
41e: 89 81 ldd r24, Y+1 ; 0x01
420: 8e 5f subi r24, 0xFE ; 254
422: 89 83 std Y+1, r24 ; 0x01
}
424: 89 81 ldd r24, Y+1 ; 0x01
426: 85 3f cpi r24, 0xF5 ; 245
428: 08 f4 brcc .+2 ; 0x42c <taskSignal+0x42>
42a: f9 cf rjmp .-14 ; 0x41e <taskSignal+0x34>
while( i<245 );
But using -Os results in the following code:
262: 80 e0 ldi r24, 0x00 ; 0
do
{
i+=2;
264: 8a 5f subi r24, 0xFA ; 250
}
266: 85 3f cpi r24, 0xF5 ; 245
268: e8 f3 brcs .-6 ; 0x264 <taskSignal+0x8>
while( i<245 );
Please note how the substraction of -2 is optimized in something other.
The compiler said:
avr-gcc (GCC) 3.4.6 (Gentoo 3.4.6, ssp-3.4.5-1.0, pie-8.7.9)
Copyright (C) 2006 Free Software Foundation, Inc.
The line calling it was:
avr-gcc -c -mmcu=attiny26 -I. -g -DF_CPU=8000000UL -Os -Wall
-Wstrict-prototypes -Wa,-adhlns=tester.lst -MD -MP -MF .dep/tester.o.d
tester.c -o tester.o
--
Summary: Optimizaition on AVR target breaks code.
Product: gcc
Version: 3.4.6
Status: UNCONFIRMED
Severity: critical
Priority: P3
Component: tree-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ralf-engels at gmx dot de
GCC target triplet: avr
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28894