public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jleahy+gcc at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/57448] New: GCSE generates incorrect code with acquire barrier
Date: Wed, 29 May 2013 09:26:00 -0000	[thread overview]
Message-ID: <bug-57448-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 57448
           Summary: GCSE generates incorrect code with acquire barrier
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jleahy+gcc at gmail dot com

The following code:

extern int seq;
extern int data;

int reader() {
    int data_copy;
    int seq_copy;
    for (int i=0; i<10; ++i) {
        __atomic_load(&seq, &seq_copy, __ATOMIC_ACQUIRE);
        data_copy = data;
    }
    return data_copy + seq_copy;
}

Compiled with "g++ -masm=intel -std=c++11 -S -O -fgcse test.cpp" using gcc
4.8.0 on x86_64 Linux, generates the following assembler:

    .file   "test.cpp"
    .intel_syntax noprefix
    .text
    .globl  _Z6readerv
    .type   _Z6readerv, @function
_Z6readerv:
.LFB0:
    .cfi_startproc
    mov edx, 10
    mov ecx, DWORD PTR data[rip]
.L3:
    mov eax, DWORD PTR seq[rip]
    sub edx, 1
    jne .L3
    add eax, ecx
    ret
    .cfi_endproc
.LFE0:
    .size   _Z6readerv, .-_Z6readerv
    .ident  "GCC: (GNU) 4.8.0"
    .section    .note.GNU-stack,"",@progbits

Here the load of data was hoisted above the load of seq, which is in violation
of the acquire memory ordering.

On the wiki here (http://gcc.gnu.org/wiki/Atomic/GCCMM/Optimizations/Details)
it says "acquire is a barrier to hoisting code" and "CSE basically hoists
subexpressions into temporaries, so it would have the same logic apply as PRE:
valid across release, invalid across an acquire."


             reply	other threads:[~2013-05-29  9:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-29  9:26 jleahy+gcc at gmail dot com [this message]
2013-05-29  9:34 ` [Bug rtl-optimization/57448] " rguenth at gcc dot gnu.org
2013-05-29 20:21 ` steven at gcc dot gnu.org
2013-05-29 22:07 ` steven at gcc dot gnu.org
2021-08-22 20:03 ` pinskia at gcc dot gnu.org
2021-08-22 20:04 ` pinskia at gcc dot gnu.org

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