From patchwork Tue Jul 11 18:39:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Monakov X-Patchwork-Id: 786804 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3x6W8k3Sm6z9s7C for ; Wed, 12 Jul 2017 04:39:45 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="YfKiBPjm"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:in-reply-to:message-id:references:mime-version :content-type; q=dns; s=default; b=MUZUHLpVZMcSpQi/g07I5066xrg+Q S+S+XbMCuYQZwQ/WIHelsVTkSdLIwekxl817XVLlEqwVO/nTR9kLBl0/q9cDwyn9 FWjRfzn70ETvpe/qNRUIrjfGfN/dDY0inByKV91ulnOGHPKOutLaTFXsjJGFqvCZ TDdFtXcbDDeE4U= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:in-reply-to:message-id:references:mime-version :content-type; s=default; bh=ME5LxHbcfUdiLR9hxEfVQ8LTvHw=; b=YfK iBPjmrmH0oZKrZvGv/qdqvE65hsFAfdAG7hA6lX04N3pz6+PyGIXAiSYORaAYZpE sT47Wnf5thQgH9QdQWWXGh6e7wDYuaM0QQzuQ6/4909kUeYIi9MG0jrBHiP5KryB gFSLEpPF/2p9baKyaRcCUrKh/PgOzWCXAza+BpIs= Received: (qmail 67204 invoked by alias); 11 Jul 2017 18:39:38 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 67193 invoked by uid 89); 11 Jul 2017 18:39:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: smtp.ispras.ru Received: from bran.ispras.ru (HELO smtp.ispras.ru) (83.149.199.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Jul 2017 18:39:35 +0000 Received: from monopod.intra.ispras.ru (monopod.intra.ispras.ru [10.10.3.121]) by smtp.ispras.ru (Postfix) with ESMTP id EC9D35FB8B for ; Tue, 11 Jul 2017 21:39:32 +0300 (MSK) Date: Tue, 11 Jul 2017 21:39:07 +0300 (MSK) From: Alexander Monakov To: gcc-patches@gcc.gnu.org Subject: Re: [PATCH 1/2] x86, s390: add compiler memory barriers when expanding atomic_thread_fence (PR 80640) In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20.13 (LNX 116 2015-12-14) MIME-Version: 1.0 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 ())