public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/57448] New: GCSE generates incorrect code with acquire barrier
@ 2013-05-29  9:26 jleahy+gcc at gmail dot com
  2013-05-29  9:34 ` [Bug rtl-optimization/57448] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: jleahy+gcc at gmail dot com @ 2013-05-29  9:26 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-08-22 20:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-29  9:26 [Bug rtl-optimization/57448] New: GCSE generates incorrect code with acquire barrier jleahy+gcc at gmail dot com
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

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