[cfe-dev] __sync_synchronize doesn't generate a memory barrier

Chris Lattner clattner at apple.com
Sun May 22 09:52:57 PDT 2011


Adding Owen :)

-Chris

On May 9, 2011, at 10:38 AM, Arlen Cox wrote:

> Why does __sync_synchronize() not generate a mfence instruction on x86
> and x86_64?  I recognize that Apple gcc does not do this either, but I
> believe this is a bug in Apple gcc as well.  More recent versions of
> gcc implement a correct behavior (mfence on x86_64 and lock orl $0,
> (%esp) on x86), but clang emits no code for this operation.
> 
> LLVM supports an instruction that emits the correct memory barrier:
>  call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true)
> but Clang uses the following, which seems to have no effect on x86:
>  call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 false)
> 
> This matters for multi-threaded code as memory barriers are the only
> way we can force an ordering on loads and stores.
> 
> Thanks,
> Arlen
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list