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

* [Bug rtl-optimization/57448] GCSE generates incorrect code with acquire barrier
  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 ` rguenth at gcc dot gnu.org
  2013-05-29 20:21 ` steven at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-05-29  9:34 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-05-29
                 CC|                            |stevenb.gcc at gmail dot com
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
;; _7 = __atomic_load_4 (&seq, 2);

(insn 13 12 0 (set (reg:SI 61 [ D.2227 ])
        (mem/v:SI (symbol_ref:DI ("seq") [flags 0x40]  <var_decl 0x7ffff6e67558
seq>) [-1 S4 A32])) t.c:8 -1
     (nil))

the MEM alias-set of -1 (ALIAS_SET_MEMORY_BARRIER) is supposed to prevent this,
but PRE does not know about this special property (it should "kill" all refs
crossing it).


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

* [Bug rtl-optimization/57448] GCSE generates incorrect code with acquire barrier
  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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: steven at gcc dot gnu.org @ 2013-05-29 20:21 UTC (permalink / raw)
  To: gcc-bugs

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

Steven Bosscher <steven at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|jleahy+gcc at gmail dot com,       |steven at gcc dot gnu.org
                   |stevenb.gcc at gmail dot com       |
           Assignee|unassigned at gcc dot gnu.org      |steven at gcc dot gnu.org


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

* [Bug rtl-optimization/57448] GCSE generates incorrect code with acquire barrier
  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
  4 siblings, 0 replies; 6+ messages in thread
From: steven at gcc dot gnu.org @ 2013-05-29 22:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Steven Bosscher <steven at gcc dot gnu.org> ---
Created attachment 30219
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30219&action=edit
Handle ALIAS_SET_MEMORY_BARRIER loads and stores

It feels like too-big-a-hammer but I don't see any other way...


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

* [Bug rtl-optimization/57448] GCSE generates incorrect code with acquire barrier
  2013-05-29  9:26 [Bug rtl-optimization/57448] New: GCSE generates incorrect code with acquire barrier jleahy+gcc at gmail dot com
                   ` (2 preceding siblings ...)
  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
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-22 20:03 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |8.0
           Keywords|                            |wrong-code

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

* [Bug rtl-optimization/57448] GCSE generates incorrect code with acquire barrier
  2013-05-29  9:26 [Bug rtl-optimization/57448] New: GCSE generates incorrect code with acquire barrier jleahy+gcc at gmail dot com
                   ` (3 preceding siblings ...)
  2021-08-22 20:03 ` pinskia at gcc dot gnu.org
@ 2021-08-22 20:04 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-22 20:04 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lucenadeveloper at gmail dot com

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 70889 has been marked as a duplicate of this bug. ***

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