From patchwork Thu Apr 27 16:22:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick O'Neill X-Patchwork-Id: 88312 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp390098vqo; Thu, 27 Apr 2023 09:28:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7IZTy1Uea9pnJb5rhbZMDfCm6VfD3OpjzbfF89jlOJoxF38LpNSnooXrotFgDQ6m/IgWXi X-Received: by 2002:a17:906:3a8f:b0:953:37d9:282f with SMTP id y15-20020a1709063a8f00b0095337d9282fmr5167577ejd.38.1682612924051; Thu, 27 Apr 2023 09:28:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682612924; cv=none; d=google.com; s=arc-20160816; b=ZOSMhpqkw37SHzhAu0eiGO86PKWtr0YonfYH3bLpQKZgBAFM5s63uuzJ1OqmueGVPf gww16Bt6Tlo20s1SGE5BgqX4wRYWXqcSgYFUyiMPjtwTjiJU8rhBHzvmUuUIgDpRDLWR szYbCNzGyJiD+ZeAxGG0TDXkU5q01M6hjcRUR9olUOrve8/HgLNbx95CpOGmt1/dnHul PVDZLKNk9cLVv4MjQf6FOPuFw5gs2kh5SvWfcXyOXtaEslxFwBojt6C5dHTrrZ3K9C51 aUSVYTGVH/54/4DxRXRlHk9KaKJaKmfiLFF7HRv19+pdDwSzaVZlARK2ccPZVR4kkHPi FWow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dmarc-filter:delivered-to; bh=vXnEuSJcUm5WuWYOJ9yr9SOJ0ChWceAC7VRnimbg1a0=; b=r9Vf4NJQ0LV2IoBgvNmoR/wvPfsDTyrIXEllFGWEkftkydSLoaO3xO5SDVbhgtanUI PF3GFyvu4cUj84EE+tevWVl5f20rBCAwR57wzyzvU/Vg0Rv9NIqRa45528FtpLQqAmGa ChW3BsL9/6ZXt6gzDVna+OqD/sKeq+ArgcvoIKWvSEdr8+0PjnP/iLzAjYZsnFwltKLV 8ol2Y3Vh8fdMS4MhB3/P2zFWKe4HftVr+2aB1zKAmLd/REFBc3KOOUtPxPYz9h8/1djD d2NOZZHnGQwVra8MjJv4qK/b3Vt35BktokcdW2wz6mYeljrUxwkUgGqcEIhA9k1iJqgo Bs9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=XtTNFCd1; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ga34-20020a1709070c2200b0094f071f8246si17444316ejc.377.2023.04.27.09.28.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 09:28:44 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=XtTNFCd1; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CE6E03896C07 for ; Thu, 27 Apr 2023 16:25:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by sourceware.org (Postfix) with ESMTPS id CD25F3857350 for ; Thu, 27 Apr 2023 16:24:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CD25F3857350 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pl1-x641.google.com with SMTP id d9443c01a7336-1a6f0d8cdfeso68012095ad.2 for ; Thu, 27 Apr 2023 09:24:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1682612659; x=1685204659; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vXnEuSJcUm5WuWYOJ9yr9SOJ0ChWceAC7VRnimbg1a0=; b=XtTNFCd1/MvbGptjbj9b/V4Tt5A91ALoA4FKoBQc56dtrKKpcADPrMjJ5Z08pTGq/t 1fyUw2tCmWFbrwEsaCbFj4EJQBMJiO+Z9R+SYIA4gVfkW55z/aFtAHygNogwm1j85dpa FK/CC2PObQI5VMjZkscln1gZ+1wzf2RI7oljLSgFhfvjo+QTqUEme5pszC7Rc6CerfL8 pxaeQOHUaX26nUSPs0eG3hPRIEdb+ZLaMo6UtdGHRMVUPXVEv3KH626ER95uau5dVUpG 4ZSrLQCzJAccvodymCucKcMYfDalEUr0C60tNKqjTCAvyIwBOl/BHpN86H4kn6gIZSj7 3ykA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682612659; x=1685204659; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vXnEuSJcUm5WuWYOJ9yr9SOJ0ChWceAC7VRnimbg1a0=; b=XRuObzUIRZ8aJw12mJ4UJbiB9HYAfN0StmYfG6aIlGL/ZgSHcynYY7GpeyD42Mj9Rj 4QTY3jSUyX17ByL+fWHik3VyMs1T82degahzDaADUqONUqy55Kuiez3qyKYcInp/DIhU +QIkwZKc2S7+P4gtcLE3tEygKEHecKScF6TM6CfJ4tt/Wj6TpNev2cgoljLlhOcvgYmy 8aXElvSI6VVs+rI1P1Dt79rlkBO3h8bMVht0YSG8xqEFvlHDBPkJYWXtuKvFodAqIys7 5/pl/JGSoT5oOnySyZhQGmvmv7qRCNaEG5e9ADTFCXGDkkuDdhsN8P56iZcJNWdEWk/h lEeg== X-Gm-Message-State: AC+VfDxJPFGftkaT+qBD706LmijRFCNywEcMPyP/MFzByT/JtuUJZZCn +97ghN7Bciu6k4OOcleBQtzPZYc27/O0Ewio6bUi/yg/Jqc= X-Received: by 2002:a17:903:1250:b0:1a9:79ea:ff15 with SMTP id u16-20020a170903125000b001a979eaff15mr2164331plh.6.1682612658710; Thu, 27 Apr 2023 09:24:18 -0700 (PDT) Received: from patrick-ThinkPad-X1-Carbon-Gen-8.hq.rivosinc.com ([50.221.140.188]) by smtp.gmail.com with ESMTPSA id n19-20020a170902969300b001a6db2bef16sm11815906plp.303.2023.04.27.09.24.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 09:24:18 -0700 (PDT) From: Patrick O'Neill To: gcc-patches@gcc.gnu.org Cc: palmer@rivosinc.com, gnu-toolchain@rivosinc.com, vineetg@rivosinc.com, andrew@sifive.com, kito.cheng@sifive.com, dlustig@nvidia.com, cmuellner@gcc.gnu.org, andrea@rivosinc.com, hboehm@google.com, jeffreyalaw@gmail.com, Patrick O'Neill Subject: [PATCH v5 07/11] RISC-V: Eliminate AMO op fences Date: Thu, 27 Apr 2023 09:22:57 -0700 Message-Id: <20230427162301.1151333-8-patrick@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230427162301.1151333-1-patrick@rivosinc.com> References: <20230414170942.1695672-1-patrick@rivosinc.com> <20230427162301.1151333-1-patrick@rivosinc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764347529640155104?= X-GMAIL-MSGID: =?utf-8?q?1764347529640155104?= Atomic operations with the appropriate bits set already enfore release semantics. Remove unnecessary release fences from atomic ops. This change brings AMO ops in line with table A.6 of the ISA manual. 2023-04-27 Patrick O'Neill gcc/ChangeLog: * config/riscv/riscv.cc (riscv_memmodel_needs_amo_release): Change function name. (riscv_print_operand): Remove unneeded %F case. * config/riscv/sync.md: Remove unneeded fences. Signed-off-by: Patrick O'Neill --- gcc/config/riscv/riscv.cc | 16 +++++----------- gcc/config/riscv/sync.md | 12 ++++++------ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index d46781d8981..9eba03ac189 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -4312,11 +4312,11 @@ riscv_memmodel_needs_amo_acquire (enum memmodel model) } } -/* Return true if a FENCE should be emitted to before a memory access to - implement the release portion of memory model MODEL. */ +/* Return true if the .RL suffix should be added to an AMO to implement the + release portion of memory model MODEL. */ static bool -riscv_memmodel_needs_release_fence (enum memmodel model) +riscv_memmodel_needs_amo_release (enum memmodel model) { switch (model) { @@ -4342,7 +4342,6 @@ riscv_memmodel_needs_release_fence (enum memmodel model) 'R' Print the low-part relocation associated with OP. 'C' Print the integer branch condition for comparison OP. 'A' Print the atomic operation suffix for memory model OP. - 'F' Print a FENCE if the memory model requires a release. 'z' Print x0 if OP is zero, otherwise print OP normally. 'i' Print i if the operand is not a register. 'S' Print shift-index of single-bit mask OP. @@ -4504,19 +4503,14 @@ riscv_print_operand (FILE *file, rtx op, int letter) case 'A': if (riscv_memmodel_needs_amo_acquire (model) - && riscv_memmodel_needs_release_fence (model)) + && riscv_memmodel_needs_amo_release (model)) fputs (".aqrl", file); else if (riscv_memmodel_needs_amo_acquire (model)) fputs (".aq", file); - else if (riscv_memmodel_needs_release_fence (model)) + else if (riscv_memmodel_needs_amo_release (model)) fputs (".rl", file); break; - case 'F': - if (riscv_memmodel_needs_release_fence (model)) - fputs ("fence iorw,ow; ", file); - break; - case 'i': if (code != REG) fputs ("i", file); diff --git a/gcc/config/riscv/sync.md b/gcc/config/riscv/sync.md index 1acb78a9ae4..9a3b57bd09f 100644 --- a/gcc/config/riscv/sync.md +++ b/gcc/config/riscv/sync.md @@ -91,9 +91,9 @@ (match_operand:SI 2 "const_int_operand")] ;; model UNSPEC_SYNC_OLD_OP))] "TARGET_ATOMIC" - "%F2amo.%A2 zero,%z1,%0" + "amo.%A2\tzero,%z1,%0" [(set_attr "type" "atomic") - (set (attr "length") (const_int 8))]) + (set (attr "length") (const_int 4))]) (define_insn "atomic_fetch_" [(set (match_operand:GPR 0 "register_operand" "=&r") @@ -105,9 +105,9 @@ (match_operand:SI 3 "const_int_operand")] ;; model UNSPEC_SYNC_OLD_OP))] "TARGET_ATOMIC" - "%F3amo.%A3 %0,%z2,%1" + "amo.%A3\t%0,%z2,%1" [(set_attr "type" "atomic") - (set (attr "length") (const_int 8))]) + (set (attr "length") (const_int 4))]) (define_insn "subword_atomic_fetch_strong_" [(set (match_operand:SI 0 "register_operand" "=&r") ;; old value at mem @@ -247,9 +247,9 @@ (set (match_dup 1) (match_operand:GPR 2 "register_operand" "0"))] "TARGET_ATOMIC" - "%F3amoswap.%A3 %0,%z2,%1" + "amoswap.%A3\t%0,%z2,%1" [(set_attr "type" "atomic") - (set (attr "length") (const_int 8))]) + (set (attr "length") (const_int 4))]) (define_expand "atomic_exchange" [(match_operand:SHORT 0 "register_operand") ;; old value at mem