public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/55492] New: __atomic_load doesn't match ACQUIRE memory model
@ 2012-11-27 16:13 yvan.roux at linaro dot org
  2012-11-28 20:06 ` [Bug target/55492] " amacleod at redhat dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: yvan.roux at linaro dot org @ 2012-11-27 16:13 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 55492
           Summary: __atomic_load doesn't match ACQUIRE memory model
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: yvan.roux@linaro.org


Created attachment 28796
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28796
Generic expansion patch proposal

Compiling this code for ARMv7

int v;

int foo()
{
  return __atomic_load_n (&v, __ATOMIC_ACQUIRE);
}

generates a data memory barrier defore the load:

foo:
    movw    r3, #:lower16:v
    movt    r3, #:upper16:v
    dmb     sy
    ldr     r0, [r3, #0]
    bx      lr

But, the `Acquire’ semantics imply that no reads in the current thread
dependent on the value currently loaded can be reordered before this load.
Thus, the barrier needs to be after the load and not before.

The issue seems to be in expand_atomic_load which put a memory fence before
the load in any memory model. The attached patch fixes the problem.


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

* [Bug target/55492] __atomic_load doesn't match ACQUIRE memory model
  2012-11-27 16:13 [Bug target/55492] New: __atomic_load doesn't match ACQUIRE memory model yvan.roux at linaro dot org
@ 2012-11-28 20:06 ` amacleod at redhat dot com
  2012-11-29  9:51 ` yvan.roux at linaro dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: amacleod at redhat dot com @ 2012-11-28 20:06 UTC (permalink / raw)
  To: gcc-bugs


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

Andrew Macleod <amacleod at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |amacleod at redhat dot com

--- Comment #1 from Andrew Macleod <amacleod at redhat dot com> 2012-11-28 20:06:46 UTC ---
Yeah, its not right as is.

Patch is OK.


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

* [Bug target/55492] __atomic_load doesn't match ACQUIRE memory model
  2012-11-27 16:13 [Bug target/55492] New: __atomic_load doesn't match ACQUIRE memory model yvan.roux at linaro dot org
  2012-11-28 20:06 ` [Bug target/55492] " amacleod at redhat dot com
@ 2012-11-29  9:51 ` yvan.roux at linaro dot org
  2012-11-29 15:20 ` amacleod at redhat dot com
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: yvan.roux at linaro dot org @ 2012-11-29  9:51 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #2 from Yvan Roux <yvan.roux at linaro dot org> 2012-11-29 09:51:41 UTC ---
Thanks Andrew for the review, I can't commit the patch myself,
can you do it, or have I to post it on the mailing list ?


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

* [Bug target/55492] __atomic_load doesn't match ACQUIRE memory model
  2012-11-27 16:13 [Bug target/55492] New: __atomic_load doesn't match ACQUIRE memory model yvan.roux at linaro dot org
  2012-11-28 20:06 ` [Bug target/55492] " amacleod at redhat dot com
  2012-11-29  9:51 ` yvan.roux at linaro dot org
@ 2012-11-29 15:20 ` amacleod at redhat dot com
  2012-12-13 21:01 ` rth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: amacleod at redhat dot com @ 2012-11-29 15:20 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #3 from Andrew Macleod <amacleod at redhat dot com> 2012-11-29 15:20:04 UTC ---
Send it to the patches list. 

As long as you have a waiver on file allowing the code to be used I can check
it in.


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

* [Bug target/55492] __atomic_load doesn't match ACQUIRE memory model
  2012-11-27 16:13 [Bug target/55492] New: __atomic_load doesn't match ACQUIRE memory model yvan.roux at linaro dot org
                   ` (2 preceding siblings ...)
  2012-11-29 15:20 ` amacleod at redhat dot com
@ 2012-12-13 21:01 ` rth at gcc dot gnu.org
  2012-12-13 21:17 ` rth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rth at gcc dot gnu.org @ 2012-12-13 21:01 UTC (permalink / raw)
  To: gcc-bugs


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

Richard Henderson <rth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2012-12-13
                 CC|                            |rth at gcc dot gnu.org
         AssignedTo|unassigned at gcc dot       |rth at gcc dot gnu.org
                   |gnu.org                     |
   Target Milestone|---                         |4.7.3
     Ever Confirmed|0                           |1

--- Comment #4 from Richard Henderson <rth at gcc dot gnu.org> 2012-12-13 21:01:32 UTC ---
Confirmed.  While the code for the above patch is good,
I'm going to update some comments at the same time.


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

* [Bug target/55492] __atomic_load doesn't match ACQUIRE memory model
  2012-11-27 16:13 [Bug target/55492] New: __atomic_load doesn't match ACQUIRE memory model yvan.roux at linaro dot org
                   ` (3 preceding siblings ...)
  2012-12-13 21:01 ` rth at gcc dot gnu.org
@ 2012-12-13 21:17 ` rth at gcc dot gnu.org
  2012-12-13 21:18 ` rth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rth at gcc dot gnu.org @ 2012-12-13 21:17 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #5 from Richard Henderson <rth at gcc dot gnu.org> 2012-12-13 21:16:50 UTC ---
Author: rth
Date: Thu Dec 13 21:16:45 2012
New Revision: 194490

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194490
Log:
PR middle-end/55492

        * optabs.c (expand_atomic_load): Emit acquire barrier after the load.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/optabs.c


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

* [Bug target/55492] __atomic_load doesn't match ACQUIRE memory model
  2012-11-27 16:13 [Bug target/55492] New: __atomic_load doesn't match ACQUIRE memory model yvan.roux at linaro dot org
                   ` (4 preceding siblings ...)
  2012-12-13 21:17 ` rth at gcc dot gnu.org
@ 2012-12-13 21:18 ` rth at gcc dot gnu.org
  2012-12-13 21:19 ` [Bug middle-end/55492] " rth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rth at gcc dot gnu.org @ 2012-12-13 21:18 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #6 from Richard Henderson <rth at gcc dot gnu.org> 2012-12-13 21:17:55 UTC ---
Author: rth
Date: Thu Dec 13 21:17:52 2012
New Revision: 194491

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194491
Log:
PR middle-end/55492

        * optabs.c (expand_atomic_load): Emit acquire barrier after the load.

Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/optabs.c


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

* [Bug middle-end/55492] __atomic_load doesn't match ACQUIRE memory model
  2012-11-27 16:13 [Bug target/55492] New: __atomic_load doesn't match ACQUIRE memory model yvan.roux at linaro dot org
                   ` (5 preceding siblings ...)
  2012-12-13 21:18 ` rth at gcc dot gnu.org
@ 2012-12-13 21:19 ` rth at gcc dot gnu.org
  2012-12-14 10:14 ` yvan.roux at linaro dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rth at gcc dot gnu.org @ 2012-12-13 21:19 UTC (permalink / raw)
  To: gcc-bugs


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

Richard Henderson <rth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
             Status|ASSIGNED                    |RESOLVED
          Component|target                      |middle-end
         Resolution|                            |FIXED

--- Comment #7 from Richard Henderson <rth at gcc dot gnu.org> 2012-12-13 21:19:38 UTC ---
Fixed.


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

* [Bug middle-end/55492] __atomic_load doesn't match ACQUIRE memory model
  2012-11-27 16:13 [Bug target/55492] New: __atomic_load doesn't match ACQUIRE memory model yvan.roux at linaro dot org
                   ` (6 preceding siblings ...)
  2012-12-13 21:19 ` [Bug middle-end/55492] " rth at gcc dot gnu.org
@ 2012-12-14 10:14 ` yvan.roux at linaro dot org
  2012-12-14 15:33 ` amacleod at redhat dot com
  2012-12-14 16:29 ` rth at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: yvan.roux at linaro dot org @ 2012-12-14 10:14 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #8 from Yvan Roux <yvan.roux at linaro dot org> 2012-12-14 10:14:15 UTC ---
Hi Richard,

Thanks for having applied and cleaned my patch.

Regarding this cleanup, if we want to be consistant I think we have to remove
the memory model test in expand_atomic_store (see the peace of patch below) as
the atomic_store valid memory model variants are RELAXED, SEQ_CST, and RELEASE
and that expand_mem_thread_fence doesn't emit any barrier in the RELEASE model
case.

Thanks,
Yvan

@@ -7537,8 +7537,7 @@ expand_atomic_store (rtx mem, rtx val, enum memmodel
model, bool use_release)
     }

   /* Otherwise assume stores are atomic, and emit the proper barriers.  */
-  if (model == MEMMODEL_SEQ_CST || model == MEMMODEL_RELEASE)
-    expand_mem_thread_fence (model);
+  expand_mem_thread_fence (model);

   emit_move_insn (mem, val);


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

* [Bug middle-end/55492] __atomic_load doesn't match ACQUIRE memory model
  2012-11-27 16:13 [Bug target/55492] New: __atomic_load doesn't match ACQUIRE memory model yvan.roux at linaro dot org
                   ` (7 preceding siblings ...)
  2012-12-14 10:14 ` yvan.roux at linaro dot org
@ 2012-12-14 15:33 ` amacleod at redhat dot com
  2012-12-14 16:29 ` rth at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: amacleod at redhat dot com @ 2012-12-14 15:33 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #9 from Andrew Macleod <amacleod at redhat dot com> 2012-12-14 15:32:52 UTC ---
Took me a second.. I presume you meant that expand_mem_thread_fence doesn't
emit anything for RELAXED mode...

Yes, since __atomic_store has already been verified by
expand_builtin_atomic_store() to only be one of the 3 valid cases, there should
not be a need for the if statement guarding the expand_mem_thread_fence.


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

* [Bug middle-end/55492] __atomic_load doesn't match ACQUIRE memory model
  2012-11-27 16:13 [Bug target/55492] New: __atomic_load doesn't match ACQUIRE memory model yvan.roux at linaro dot org
                   ` (8 preceding siblings ...)
  2012-12-14 15:33 ` amacleod at redhat dot com
@ 2012-12-14 16:29 ` rth at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: rth at gcc dot gnu.org @ 2012-12-14 16:29 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #10 from Richard Henderson <rth at gcc dot gnu.org> 2012-12-14 16:29:34 UTC ---
Committed the suggested tweak, thanks.


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

end of thread, other threads:[~2012-12-14 16:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-27 16:13 [Bug target/55492] New: __atomic_load doesn't match ACQUIRE memory model yvan.roux at linaro dot org
2012-11-28 20:06 ` [Bug target/55492] " amacleod at redhat dot com
2012-11-29  9:51 ` yvan.roux at linaro dot org
2012-11-29 15:20 ` amacleod at redhat dot com
2012-12-13 21:01 ` rth at gcc dot gnu.org
2012-12-13 21:17 ` rth at gcc dot gnu.org
2012-12-13 21:18 ` rth at gcc dot gnu.org
2012-12-13 21:19 ` [Bug middle-end/55492] " rth at gcc dot gnu.org
2012-12-14 10:14 ` yvan.roux at linaro dot org
2012-12-14 15:33 ` amacleod at redhat dot com
2012-12-14 16:29 ` rth 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).