[backport approved but not yet applied patch for an __atomic_load problem on ARMv7 ] Date: Thu, 29 Nov 2012 16:42:41 +0100 Subject: [PATCH] Fix for PR55492 : __atomic_load doesn't match ACQUIRE memory model From: Yvan Roux List-Archive: Hi, on ARMv7, the code generated for the __atomic_load builtins in the __ATOMIC_ACQUIRE memory model, puts a memory barrier before the load, whereas the semantic of the acquire memory model implies a barrier after. The issue seems to be in expand_atomic_load which puts a memory fence before the load in any memory model. The attached patch fixes the problem. Thanks, Yvan gcc/ 2012-11-29 Yvan Roux PR target/55942 * optabs.c (expand_atomic_load): Condition the memory fence to the the right memory model. --- gcc-4.7.2/gcc/optabs.c.~1~ 2012-03-04 03:34:55.000000000 +0100 +++ gcc-4.7.2/gcc/optabs.c 2012-12-02 17:31:06.000000000 +0100 @@ -7701,12 +7701,13 @@ expand_atomic_load (rtx target, rtx mem, target = gen_reg_rtx (mode); /* Emit the appropriate barrier before the load. */ - expand_mem_thread_fence (model); + if (model == MEMMODEL_SEQ_CST) + expand_mem_thread_fence (model); emit_move_insn (target, mem); - /* For SEQ_CST, also emit a barrier after the load. */ - if (model == MEMMODEL_SEQ_CST) + /* For SEQ_CST or ACQUIRE, also emit a barrier after the load. */ + if (model == MEMMODEL_SEQ_CST || model == MEMMODEL_ACQUIRE) expand_mem_thread_fence (model); return target;