public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jim at jtan dot com" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-53842-4@http.gcc.gnu.org/bugzilla/> (raw)

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 <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.


             reply	other threads:[~2012-07-03 19:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-03 19:03 jim at jtan dot com [this message]
2012-07-04  9:27 ` [Bug target/53842] " rguenth at gcc dot gnu.org
2012-07-04 15:08 ` jim at jtan dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-53842-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).