[cfe-dev] __sync_synchronize doesn't generate a memory barrier
Arlen Cox
arlencox at gmail.com
Mon May 9 10:38:33 PDT 2011
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
More information about the cfe-dev
mailing list