public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* should sync builtins be full optimization barriers?
@ 2011-09-09  8:07 Paolo Bonzini
  2011-09-09  8:17 ` Jakub Jelinek
  0 siblings, 1 reply; 40+ messages in thread
From: Paolo Bonzini @ 2011-09-09  8:07 UTC (permalink / raw)
  To: GCC Mailing List, Jakub Jelinek, Aldy Hernandez, amacleod

Hi all,

sync builtins are described in the documentations as being full memory 
barriers, with the possible exception of __sync_lock_test_and_set. 
However, GCC is not enforcing the fact that they are also full 
_optimization_ barriers.  The RTL produced by builtins does not in 
general include a memory optimization barrier such as a set of 
(mem/v:BLK (scratch:P)).

This can cause problems with lock-free algorithms, for example this:

http://libdispatch.macosforge.org/trac/ticket/35

This can be solved either in generic code, by wrapping sync builtins 
(before and after) with an asm("":::"memory"), or in the single machine 
descriptions by adding a memory barrier in parallel to the locked 
instructions or with the ll/sc instructions.

Is the above analysis correct?  Or should the users put explicit 
compiler barriers?

Paolo

^ permalink raw reply	[flat|nested] 40+ messages in thread
* Re: should sync builtins be full optimization barriers?
@ 2011-09-15 16:20 Richard Henderson
  2011-09-15 16:26 ` Paolo Bonzini
  0 siblings, 1 reply; 40+ messages in thread
From: Richard Henderson @ 2011-09-15 16:20 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: gcc

> > I'd say they should be optimization barriers too (and at the tree level
> > they I think work that way, being represented as function calls), so if
> > they don't act as memory barriers in RTL, the *.md patterns should be
> > fixed.  The only exception should be IMHO the __SYNC_MEM_RELAXED
> > variants - if the CPU can reorder memory accesses across them at will,
> > why shouldn't the compiler be able to do the same as well?
> 
> Agreed, so we have a bug in all released versions of GCC. :(

I wouldn't go that far.  They *used* to be compiler barriers,
but clearly something broke at some point without anyone noticing.
We don't know how many versions are affected until we debug it.
For all we know it broke in 4.5 and 4.4 is fine.

There's no reference to a GCC bug report about this in the thread.
Did the folks over at the libdispatch project never think to file one?
Or does a bug report exist and my search skills are weak?


r~

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

end of thread, other threads:[~2011-09-26 18:10 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-09  8:07 should sync builtins be full optimization barriers? Paolo Bonzini
2011-09-09  8:17 ` Jakub Jelinek
2011-09-09  8:18   ` Paolo Bonzini
2011-09-09 14:23   ` Andrew MacLeod
2011-09-09 14:27     ` Paolo Bonzini
2011-09-10  1:09   ` Geert Bosch
2011-09-10  5:40     ` Paolo Bonzini
2011-09-10  6:18     ` Jakub Jelinek
2011-09-11 14:13     ` Andrew MacLeod
2011-09-11 18:23       ` Paolo Bonzini
2011-09-11 23:22         ` Andrew MacLeod
2011-09-12  7:07           ` Paolo Bonzini
2011-09-11 19:00       ` Geert Bosch
2011-09-11 19:12         ` Jakub Jelinek
2011-09-11 19:31           ` Geert Bosch
2011-09-11 19:44             ` Jakub Jelinek
2011-09-12  7:03         ` Paolo Bonzini
2011-09-12 18:40           ` Geert Bosch
2011-09-12 20:54             ` Paolo Bonzini
2011-09-12 23:19             ` Andrew MacLeod
2011-09-13  0:31               ` Ken Raeburn
2011-09-13  0:39                 ` Andy Lutomirski
2011-09-13  1:52               ` Geert Bosch
2011-09-13  6:35                 ` Paolo Bonzini
2011-09-13 14:46                   ` Eric Botcazou
2011-09-13 12:09                 ` Andrew MacLeod
2011-09-13 14:58                   ` Geert Bosch
2011-09-13 16:16                     ` Andrew MacLeod
2011-09-26 16:17                       ` Michael Matz
2011-09-26 17:32                         ` Ian Lance Taylor
2011-09-26 18:10                         ` Andrew MacLeod
2011-09-27  5:26                           ` James Dennett
2011-09-27  8:19                             ` Andrew MacLeod
2011-09-13  6:31       ` Lawrence Crowl
2011-09-13  6:20     ` Lawrence Crowl
2011-09-15 16:20 Richard Henderson
2011-09-15 16:26 ` Paolo Bonzini
2011-09-20  7:56   ` Paolo Bonzini
2011-09-24  9:24   ` Richard Guenther
2011-09-26 16:18     ` Richard Guenther

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