This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH 1/2] x86,s390: add compiler memory barriers when expanding atomic_thread_fence (PR 80640)
- From: Alexander Monakov <amonakov at ispras dot ru>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 11 Jul 2017 21:39:07 +0300 (MSK)
- Subject: Re: [PATCH 1/2] x86,s390: add compiler memory barriers when expanding atomic_thread_fence (PR 80640)
- Authentication-results: sourceware.org; auth=none
- References: <alpine.LNX.2.20.13.1705101620050.11444@monopod.intra.ispras.ru> <alpine.LNX.2.20.13.1705171248330.32526@monopod.intra.ispras.ru> <alpine.LNX.2.20.13.1705261358000.13474@monopod.intra.ispras.ru> <alpine.LNX.2.20.13.1706080053550.12986@monopod.intra.ispras.ru>
On Thu, 8 Jun 2017, Alexander Monakov wrote:
> Ping^3.
Ping^4: https://gcc.gnu.org/ml/gcc-patches/2017-05/msg00782.html
This is a wrong-code issue with C11 atomics: even if no machine barrier is
needed for a given fence type on this architecture, a compiler barrier must
be present in RTL.
Alternatively, it's possible to have a more complete and future-proof solution
by explicitly emitting a compiler barrier from the middle-end, leaving it up
to the backend to emit a machine barrier if needed. The following patch could
achieve that (but at the cost of creating slightly redundant RTL on targets
that always emit some kind of memory barrier).
* optabs.c (expand_mem_thread_fence): Always emit a compiler barrier
if using mem_thread_fence expansion.
diff --git a/gcc/optabs.c b/gcc/optabs.c
index 8fd5d91..92080c3 100644
--- a/gcc/optabs.c
+++ b/gcc/optabs.c
@@ -6297,7 +6297,11 @@ void
expand_mem_thread_fence (enum memmodel model)
{
if (targetm.have_mem_thread_fence ())
- emit_insn (targetm.gen_mem_thread_fence (GEN_INT (model)));
+ {
+ emit_insn (targetm.gen_mem_thread_fence (GEN_INT (model)));
+ if (!is_mm_relaxed (model))
+ expand_asm_memory_barrier ();
+ }
else if (!is_mm_relaxed (model))
{
if (targetm.have_memory_barrier ())