This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug target/28894] Optimizaition on AVR target breaks code.



------- Comment #3 from eweddington at cso dot atmel dot com  2006-08-30 15:06 -------
The AVR does not have an Add Immediate instruction (addi), so this is normally
done using sbi with a negative number as Andrew correctly points out.

In Ralf's unoptimized output, it correctly shows a -2 (0xFE):

41e:   89 81           ldd     r24, Y+1        ; 0x01
420:   8e 5f           subi    r24, 0xFE       ; 254

The optimized output shows a -6 (0xFA)

264:   8a 5f           subi    r24, 0xFA       ; 250

Why is this? Well, the optimizer aggressively optimizes loops that do nothing,
like the code is here:

i=0;
do 
  {
    i+=2;
  } 
while( i<245 );

Note that you only have 'i' declared as unsigned char.

The first FAQ entry in the avr-libc user manual talks about using the keyword
'volatile':
http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_volatile

If you define 'i' as volatile unsigned char, then the optimizer will not
agressively optimize your "do-nothing" loop. In fact, if you are trying to
achieve a delay using a "do-nothing" loop, then you are strongly suggested to
use the <util/delay.h> header that comes with avr-libc, which are "busy-wait
delay loops":
<http://www.nongnu.org/avr-libc/user-manual/group__util__delay.html>

GCC Bugmasters:
Please close this bug as invalid.

Eric Weddington


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28894


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]