http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53842
Bug #: 53842 Summary: avr second write to volatile register gets dropped Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassig...@gcc.gnu.org ReportedBy: j...@jtan.com Hi, I'm seeing volatile writes get dropped with avr-gcc 4.7.0 (as packaged in Debian). This didn't happen with 4.5.3. Example: ------------ $ cat test.c #define SPDR (*(volatile char *)(0x2e + 0x20)) #define SPSR (*(volatile char *)(0x2d + 0x20)) static inline char transfer(char tx) { SPDR = tx; while (!(SPSR & 0x80)) continue; return SPDR; } void foo(void) { transfer(0xff); //asm("":::"memory"); transfer(0xff); } $ avr-gcc -c -mmcu=at90usb1287 -O1 test.c -o test.o $ avr-objdump avr-objdump -d test.o test.o: file format elf32-avr Disassembly of section .text: 00000000 <foo>: 0: 8f ef ldi r24, 0xFF ; 255 2: 8e bd out 0x2e, r24 ; 46 4: 0d b4 in r0, 0x2d ; 45 6: 07 fe sbrs r0, 7 8: 00 c0 rjmp .+0 ; 0xa <foo+0xa> a: 8e b5 in r24, 0x2e ; 46 c: 0d b4 in r0, 0x2d ; 45 e: 07 fe sbrs r0, 7 10: 00 c0 rjmp .+0 ; 0x12 <foo+0x12> 12: 8e b5 in r24, 0x2e ; 46 14: 08 95 ret ------------ Note only one "out" there. If I compile that same code on 4.5.3, or uncomment that memory barrier and compile on 4.7.0, I get the correct code: ------------ 0: 8f ef ldi r24, 0xFF ; 255 2: 8e bd out 0x2e, r24 ; 46 4: 0d b4 in r0, 0x2d ; 45 6: 07 fe sbrs r0, 7 8: 00 c0 rjmp .+0 ; 0xa <foo+0xa> a: 8e b5 in r24, 0x2e ; 46 c: 8f ef ldi r24, 0xFF ; 255 e: 8e bd out 0x2e, r24 ; 46 10: 0d b4 in r0, 0x2d ; 45 12: 07 fe sbrs r0, 7 14: 00 c0 rjmp .+0 ; 0x16 <foo+0x16> 16: 8e b5 in r24, 0x2e ; 46 18: 08 95 ret ------------- This seems similar to pr53085, but that bug was listed as existing on 4.5 as well, while this one seems to be a regression.