From patchwork Fri Apr 14 17:09:38 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: 83530 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp537882vqo; Fri, 14 Apr 2023 10:16:12 -0700 (PDT) X-Google-Smtp-Source: AKy350b8CW1yv9TYMLRa9CE1ATnD6DPKi2LJo7WVMOF/iK/Ml5lPoxD1Dz6wWCSvrEESu8Ljk1sl X-Received: by 2002:aa7:cad9:0:b0:504:894b:1bc9 with SMTP id l25-20020aa7cad9000000b00504894b1bc9mr6568619edt.26.1681492572164; Fri, 14 Apr 2023 10:16:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681492572; cv=none; d=google.com; s=arc-20160816; b=O8F4iHoe2/BrJsP6wWfQM44FA83QEReqlc58OCjDPXl2W7300wpbmYbfsGrvi6nyor bszA6qqe26Vxb0btGnjGoRmgIaZn/h2COkQpS+LVJZwlt/TxvS13Njzfit2HNd4hDOza 5Pa1BVfq0U2ZgGypb0MXaG5odQm3Hf8L8MCVU8IuV2V/Wn/iO3BWwcZqgBf+en/nZLlG F5+dBkHwm2tkUSw55vcNztyF3AqYMCHdZY/ZnxS3b55FftNIC3xyQxPVm0kuhL0YoOk7 VShdwhRuUpbH7Rt8/L3VAiYpN2GGlSEuXuBIapff13jCv9OOHekrswa9kN+OiAuXUIH+ VQWg== 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=P9Da4sGTXFtl1RlbfN0nZAdSV4+gLUU/Cs6PMOmhG0U=; b=EAj0LO8MIbA0yjuukj1vheqYNdQPX10Y6EBJp484lBaALLbp8V/LrIPNWPh3L3+yb/ d1A+CZgPee9atmDSUhHiSH77qmuskzOZOQr4F4tM7CwiwCepI1322otPDjrjEcD4gG3q dla6GrHdN8qzyRx1fZ5yHidhMJ/jmz87dXibtIVhkS4qFS4be7BZ9GOkV8Kh9CZwO71X qH5wKBLk5rq5NkG7EDgvZElKFL062ny6Fp+gWz8UvKSc5I6uuLvb48JDQzIssGPG5XS+ kyrn9hd/d56O+haf21IvJcHHS90UiLkke1IcjYUuJPA+Hgp1ZL06VXN3IuEzOqVxygGF 0WSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=ESyUr4qR; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id fq5-20020a1709069d8500b0094955fd34f6si5007003ejc.216.2023.04.14.10.16.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 10:16:12 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=ESyUr4qR; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 9C80738768BE for ; Fri, 14 Apr 2023 17:12:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by sourceware.org (Postfix) with ESMTPS id 7A8CC3857714 for ; Fri, 14 Apr 2023 17:10:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7A8CC3857714 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-pf1-x444.google.com with SMTP id d2e1a72fcca58-63b509fe13eso394155b3a.1 for ; Fri, 14 Apr 2023 10:10:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681492251; x=1684084251; 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=P9Da4sGTXFtl1RlbfN0nZAdSV4+gLUU/Cs6PMOmhG0U=; b=ESyUr4qRhrasq7sZM94NoaRcciMo8ezfN9PVUBbWWWkPgvjm7U21R6en4ROIupCmDx dMKxVG8YuRfXjJKQnrfqms6kvcu25BebVONO4phHHpsL8VWVNDjAyPsXlx5XMYcf8uG5 v1HZvqfkJUDszIZ/L9/z7kDTa15YZL+xDQZu+2iCwO0IR8ZnLSgfwvqid/gjx/BwtxzQ J2NDcIPiUV77fHkIEbGdqZ7/K2SnFxkScyfRzI6a6XTrSRSvmiTbeI4QYzAcfGu5D8Ac ACme02Br013VqzbLjZJ9WTgEl8BQ21aHMMREsJhIF1jbXZXpHoD7ryarrmCNs2PnoxZM fvPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681492251; x=1684084251; 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=P9Da4sGTXFtl1RlbfN0nZAdSV4+gLUU/Cs6PMOmhG0U=; b=PVgugEL/E8hg5JzYqbURFoFy4hpocWI+bWYolZ08k4M3lgmZis2bFFLn5l6ksfbQ4K KPpo9vQ0vikviWn1vKXoOPC9tueTlSwIJJQe/rhO8dBn2dGdFHv0VtzITrAPhPOzk/FQ 1Ye36ta/xkii6ZeMTcQ6u7YtmVrl14Vuya/Aobvwa5qMY8QY0lfss7oja5VpRQsN1C7X gLHG1E06/ZFRwlWYngEcWn6zUZAu3+dKDSMdAGbM/X9QSkN9i6s2slz04M0jdF7MpOvM RigFUtjRUbNwe3kfTkdc8IsdW9KjOm/Mlo7otSzUKjvpi09alhMl2YrTXI2/rxSLG8M+ BjvQ== X-Gm-Message-State: AAQBX9cEkYRJ6jQyz0LvFHupkO0R5VVtuJj90/L6O/JkSg/kCm9yML5E jspMKKRbElHu69DsW63jAW3aQRWbZdoWnU1+uqx3yvWFYvY= X-Received: by 2002:a05:6a00:1a12:b0:63b:5c82:e21a with SMTP id g18-20020a056a001a1200b0063b5c82e21amr6403399pfv.1.1681492251324; Fri, 14 Apr 2023 10:10:51 -0700 (PDT) Received: from patrick-ThinkPad-X1-Carbon-Gen-8.hq.rivosinc.com ([50.221.140.188]) by smtp.gmail.com with ESMTPSA id 12-20020aa7924c000000b006258dd63a3fsm3271902pfp.56.2023.04.14.10.10.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 10:10:50 -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 v4 06/10] RISCV: Eliminate AMO op fences Date: Fri, 14 Apr 2023 10:09:38 -0700 Message-Id: <20230414170942.1695672-7-patrick@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230414170942.1695672-1-patrick@rivosinc.com> References: <20230410182348.2168356-1-patrick@rivosinc.com> <20230414170942.1695672-1-patrick@rivosinc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 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=ham 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?1762371882814566085?= X-GMAIL-MSGID: =?utf-8?q?1763172754984174179?= 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-14 Patrick O'Neill * riscv.cc (riscv_memmodel_needs_amo_acquire): Change function name. * riscv.cc (riscv_print_operand): Remove unneeded %F case. * 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 088b8d25773..70031b83391 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -4301,11 +4301,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) { @@ -4331,7 +4331,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. @@ -4493,19 +4492,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 eef083b06e8..fdfc56d64a1 100644 --- a/gcc/config/riscv/sync.md +++ b/gcc/config/riscv/sync.md @@ -87,9 +87,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") @@ -101,9 +101,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 "atomic_exchange" [(set (match_operand:GPR 0 "register_operand" "=&r") @@ -114,9 +114,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_insn "atomic_cas_value_strong" [(set (match_operand:GPR 0 "register_operand" "=&r")