From patchwork Fri Feb 10 22:41:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Tomsich X-Patchwork-Id: 55613 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1213314wrn; Fri, 10 Feb 2023 14:43:44 -0800 (PST) X-Google-Smtp-Source: AK7set8joMZI2iHPj3ILMljwFyAj4Mw/4ht9mjfRbnXjVAHLn93z6thDu1zaZM+36fEYAXzeypqZ X-Received: by 2002:a50:d549:0:b0:4aa:c685:2937 with SMTP id f9-20020a50d549000000b004aac6852937mr18191968edj.13.1676069024443; Fri, 10 Feb 2023 14:43:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676069024; cv=none; d=google.com; s=arc-20160816; b=ef7HSSC0Z+0GVF1So0PCXbhw1XNJC4Sn8dAE+Zl3L93BVVYHNy2EefJK5qvxy14EoT CwyIjNTb6C1dC+j0Sx3bcyo820GGJ6NmoPAT1vG/1q3ARJdbVOgtT/aQSmbeAJLTenP4 hcunu9/pEzT3OQC/7VBT178d57i3JVHwCj/quuIR/XHyAxfyzDLIemXIOtGFCLtrH3yT kfZQeyLv1FDurfhgKio7c9ZgWwy75n2vIZCBcWyWpVcJD9TXIVs7spAxXAnC6o+kR4ST kBH6ajyT9TS3A/7P3oCmlPMMCtyxlHx5Xxw1OYkgWOjOxoM41UdsrMJHqs0xd3NTY5nL N4hw== 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=i6zGWcBZ52cMsyLrbclSHuADcmLv0+USuFghN838pGY=; b=reewre9XLY2oRMhdDXBX7QTGj1Q4fNYUKt2f0C0Tt0iyfcRp306OWNHZAWIByRS2bm R/jYOR+HdXoIUibL0YhesPUTPXcmkse9HBw63O3GEhHeZSDulWeafozzhG57PLdshGKE HMlOphvkfYV6naE1CYCl4T5HhXP2CVlmrR4sRYsHYHvMX1U2w96X0Vy8j3MbufM6pG7A Cl4JlkUgKoOBBa/QtKy9yUaKEjB2b3p7hjGxQP19AC2wiZXwce007ngobUU3PJoaIIwb 5joWc2xqkM5FBj/XPELSBAItfSfuGwYv+JvslNAbV6Wp0MYIhXvGTDUpC+zhKIUXI8u1 Se7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@vrull.eu header.s=google header.b=nUe25w13; 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 j14-20020a50ed0e000000b004a0e5c32c17si6333685eds.212.2023.02.10.14.43.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 14:43:44 -0800 (PST) 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=@vrull.eu header.s=google header.b=nUe25w13; 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 64DD03896C3D for ; Fri, 10 Feb 2023 22:42:29 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id 5E5BA385483E for ; Fri, 10 Feb 2023 22:41:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5E5BA385483E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu Received: by mail-ej1-x62d.google.com with SMTP id sa10so19437243ejc.9 for ; Fri, 10 Feb 2023 14:41:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; 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=i6zGWcBZ52cMsyLrbclSHuADcmLv0+USuFghN838pGY=; b=nUe25w13cXF9xickBcAZ7dR1XEmjc1a3JhrDMGB71rpjkEqjFds1+LBSgor/TQGoFR l4ZYZkU9mgkmO0fFaXUzqo67eELPkL+tEJiznQUT0sVM28Sdwrva4yYkVrQR8ywBY4MX IUpaKkPYmNi7i2ErxrgbeIrRd3aiUzlRvdn1llEIFnqD391eddvdTcnTfGrWlntncje4 z2pYQw4LKVTMjtWMcLEMyS9oGVRBTLETm7TsC759qIWWPyc1TTtHaXKNM4CncjfSQCGj jvGKeqQejwEzg8lOPv2uARhoNJnCYAh/5ClTF2QgugC0ebBW/UVWgRtx3kRlkNcyt0y8 lqQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=i6zGWcBZ52cMsyLrbclSHuADcmLv0+USuFghN838pGY=; b=J2BN68g1nW3DBGaV8x7NVYMf6/TxhFVzEe9t5VSQzrvjRT1W1IHzf6iv/24MTZydfC LsVidRdOEqzIWPP60tmHQQKSM5xks9kMPL0LOkwiO14CwgGZaCtbj+RSw5RzIUqioV4T 8CYcNneOaI9UgM4t9VsmjtP4T351SreW23P0f1En/zogHa+ubfngmmA/ABdpbKGU9zKl z2Abve+NS2YwUXVY+Q4fHQFT1dvihQaZYJAhsBh8ozKZEJ2kXJlsKcwwtg4t5tNL1k7h WzqpWdkBNUf0fk1PRkFNTzH7fkmLc9ZDU4DHtY+4ZZghaMXU1aiHBXzB9srotfPjexLa VhuQ== X-Gm-Message-State: AO0yUKXRl9Xh1mTqxn7afngRTCmnM6MWVuxdwa2SGq+yfgYxAV5QaKwz RsYAcE/zE4neYK/PumnY1umvM9oj0fy/drZbVeU= X-Received: by 2002:a17:907:1c83:b0:884:c45f:1c04 with SMTP id nb3-20020a1709071c8300b00884c45f1c04mr23891187ejc.2.1676068916850; Fri, 10 Feb 2023 14:41:56 -0800 (PST) Received: from ubuntu-focal.. ([2a01:4f9:3a:1e26::2]) by smtp.gmail.com with ESMTPSA id c15-20020a17090603cf00b0088bd62b1cbbsm2976956eja.192.2023.02.10.14.41.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 14:41:56 -0800 (PST) From: Philipp Tomsich To: gcc-patches@gcc.gnu.org Cc: Kito Cheng , Christoph Muellner , Palmer Dabbelt , Andrew Waterman , Vineet Gupta , Philipp Tomsich Subject: [RFC PATCH v1 03/10] RISC-V: Generate czero.eqz/nez on noce_try_store_flag_mask if-conversion Date: Fri, 10 Feb 2023 23:41:43 +0100 Message-Id: <20230210224150.2801962-4-philipp.tomsich@vrull.eu> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230210224150.2801962-1-philipp.tomsich@vrull.eu> References: <20230210224150.2801962-1-philipp.tomsich@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, LIKELY_SPAM_BODY, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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?1757485753619486254?= X-GMAIL-MSGID: =?utf-8?q?1757485753619486254?= Adds a pattern to map the output of noce_try_store_flag_mask if-conversion in the combiner onto vt.maskc; the input patterns supported are similar to the following: (set (reg/v/f:DI 75 [ ]) (and:DI (neg:DI (ne:DI (reg:DI 82) (const_int 0 [0]))) (reg/v/f:DI 75 [ ]))) To ensure that the combine-pass doesn't get confused about profitability, we recognize the idiom as requiring a single instruction when the Zicond extension is present. gcc/ChangeLog: * config/riscv/riscv.cc (riscv_rtx_costs): Recongnize the idiom for conditional-zero as a single instruction for TARGET_ZICOND * config/riscv/riscv.md: Include zicond.md. * config/riscv/zicond.md: New file. gcc/testsuite/ChangeLog: * gcc.target/riscv/zicond-ne-03.c: New test. * gcc.target/riscv/zicond-ne-04.c: New test. Signed-off-by: Philipp Tomsich --- gcc/config/riscv/riscv.cc | 15 ++++++++++ gcc/config/riscv/riscv.md | 1 + gcc/config/riscv/zicond.md | 30 +++++++++++++++++++ gcc/testsuite/gcc.target/riscv/zicond-ne-03.c | 13 ++++++++ gcc/testsuite/gcc.target/riscv/zicond-ne-04.c | 13 ++++++++ 5 files changed, 72 insertions(+) create mode 100644 gcc/config/riscv/zicond.md create mode 100644 gcc/testsuite/gcc.target/riscv/zicond-ne-03.c create mode 100644 gcc/testsuite/gcc.target/riscv/zicond-ne-04.c diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index e4d3e1a3229..7e69a652fc5 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -2331,6 +2331,21 @@ riscv_rtx_costs (rtx x, machine_mode mode, int outer_code, int opno ATTRIBUTE_UN return false; case AND: + /* czero.eqz/nez */ + if ((TARGET_ZICOND) + && mode == word_mode + && GET_CODE (XEXP (x, 0)) == NEG) + { + rtx inner = XEXP (XEXP (x, 0), 0); + + if ((GET_CODE (inner) == EQ || GET_CODE (inner) == NE) + && CONST_INT_P (XEXP (inner, 1)) + && INTVAL (XEXP (inner, 1)) == 0) + { + *total = COSTS_N_INSNS (1); + return true; + } + } /* slli.uw pattern for zba. */ if (TARGET_ZBA && TARGET_64BIT && mode == DImode && GET_CODE (XEXP (x, 0)) == ASHIFT) diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index e8b5fc6644d..7c632bb4d65 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -3228,3 +3228,4 @@ (define_insn "riscv_prefetchi_" (include "generic.md") (include "sifive-7.md") (include "vector.md") +(include "zicond.md") diff --git a/gcc/config/riscv/zicond.md b/gcc/config/riscv/zicond.md new file mode 100644 index 00000000000..278e3a67802 --- /dev/null +++ b/gcc/config/riscv/zicond.md @@ -0,0 +1,30 @@ +;; Machine description for the RISC-V Zicond extension +;; Copyright (C) 2022-23 Free Software Foundation, Inc. + +;; This file is part of GCC. + +;; GCC is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. + +;; GCC is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GCC; see the file COPYING3. If not see +;; . + +(define_code_iterator eq_or_ne [eq ne]) +(define_code_attr eqz [(eq "nez") (ne "eqz")]) + +(define_insn "*czero." + [(set (match_operand:DI 0 "register_operand" "=r") + (and:DI (neg:DI (eq_or_ne:DI + (match_operand:DI 1 "register_operand" "r") + (const_int 0))) + (match_operand:DI 2 "register_operand" "r")))] + "TARGET_ZICOND" + "czero.\t%0,%2,%1") diff --git a/gcc/testsuite/gcc.target/riscv/zicond-ne-03.c b/gcc/testsuite/gcc.target/riscv/zicond-ne-03.c new file mode 100644 index 00000000000..887b1273ce7 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zicond-ne-03.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc_zicond -mabi=lp64 -mtune=thead-c906" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-O1" "-Os" "-Oz" } } */ + +long long ne3(long long a, long long b) +{ + if (a != 0) + return b; + + return 0; +} + +/* { dg-final { scan-assembler-times "czero.eqz" 1 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/zicond-ne-04.c b/gcc/testsuite/gcc.target/riscv/zicond-ne-04.c new file mode 100644 index 00000000000..6f6df06b4b9 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zicond-ne-04.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc_zicond -mabi=lp64 -mtune=thead-c906" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-Os" "-Oz" } } */ + +long long ne4(long long a, long long b) +{ + if (a != 0) + return 0; + + return b; +} + +/* { dg-final { scan-assembler-times "czero.nez" 1 } } */