From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1281 invoked by alias); 3 Jul 2012 19:03:04 -0000 Received: (qmail 1216 invoked by uid 22791); 3 Jul 2012 19:03:01 -0000 X-SWARE-Spam-Status: No, hits=-3.5 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_BJ,TW_RJ X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 03 Jul 2012 19:02:49 +0000 From: "jim at jtan dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/53842] New: avr second write to volatile register gets dropped Date: Tue, 03 Jul 2012 19:03:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jim at jtan dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-07/txt/msg00387.txt.bz2 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: unassigned@gcc.gnu.org ReportedBy: jim@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 : 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 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 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 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 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.