From patchwork Mon Oct 30 07:25:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fei Gao X-Patchwork-Id: 159539 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp2034652vqb; Mon, 30 Oct 2023 00:26:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHF9y6X1Q1+W0hDXhcUBW7OfpceQCwHJD2dEhaeNd2WFJKUuXu9wUkGR7bdjVTOLtdFJSAU X-Received: by 2002:a05:6214:d8a:b0:671:e02a:8bf6 with SMTP id e10-20020a0562140d8a00b00671e02a8bf6mr4414765qve.34.1698650782907; Mon, 30 Oct 2023 00:26:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698650782; cv=pass; d=google.com; s=arc-20160816; b=RcQd8X9ZRvln9bc2XzlYHmxVhCPJoegszOcSU2bcklvDxlDZ3crwIRmrdpR/eoqnTF lpcq+75HSdpHT4az7t8hur/QjxUJAGL4FTDxkGO32ybPhAZRywoWodKI00HT9QKUc2xv NPOoeARecL4C05pALbIhPcebYvkz026HJeNGFkmCImQ/U+EFy13fsRoqN6TZ8MSDf51K pxNeMld90P0zgJfXDuBNKMa0ondCIOdeOb+c4q5UWxTR+pYTmPgsD/79f9ZkoVBOa3wC baVJQQOa7k1F4WPbimPH+/KdpwXTUcCxtLr5O57VifopcomByNw8PMK5TbA2vUyvMzNh Fbyw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:cc:to:from:arc-filter:dmarc-filter :delivered-to; bh=wnLz2DW0gtR5tqF7uj9LO4oUDouLUWar3cFsgidDqhM=; fh=dfjB68vu7iz5i8RrpOG22UZ7WIvYTHhHfK87YX5Okjc=; b=TpbmLz5GHYLrL7X/Hr2jLRLH2qlt5iPQLsCJ9YWwPCamEm+r4n49i6ysESAPuF7wkD qII1xMJhoDqUXO6VxgyLWn6xkTaIEM0AEwriCaa3P9lhr++y8GUEC8jhGdKKWI7d/VGk zudxydEpUiy7hymArPwpDKe4hwIiAhC6ulpG376t/smZjgozsxonVXorXXqdfQoMUFf4 uT3Na2/5J4vCJIN6mpLvZSwsTqjFiYz7R0x/ybgHqxHto8fObNdkSw51BCHYmRKSy/ie KmnX8iRZpkCd0gk4qoCC6YNDuVVWvDASQuZ1JfgU2c+rVi06k+yd7NEC3u+Ewx29dG+f /KLg== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id et8-20020a056214176800b00672e2d57a6dsi1347427qvb.155.2023.10.30.00.26.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 00:26:22 -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; arc=pass (i=1); 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 478603857359 for ; Mon, 30 Oct 2023 07:26:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from zg8tmtu5ljg5lje1ms4xmtka.icoremail.net (zg8tmtu5ljg5lje1ms4xmtka.icoremail.net [159.89.151.119]) by sourceware.org (Postfix) with ESMTP id 18AE03858D20 for ; Mon, 30 Oct 2023 07:25:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 18AE03858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=eswincomputing.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=eswincomputing.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 18AE03858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=159.89.151.119 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698650755; cv=none; b=OfbSZx0tgLEgoAzaiPaLGbvfE2RHO7UW5IDvrUsav+UhytQIKgJikGgMj0sAvnwrErlD0bmG2ItBRcPhL95+/85c8d+wYr4vbLfvR9IfIz8qeiwbWaOjQZ2OLgidhAYpzpcFKSGwo/zowf8QvYbLOvCmakYttjJaYm0PXiPpT1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698650755; c=relaxed/simple; bh=VfoVAmoOHh26CAke9xClHdWoiOjsM7T0v2JHD84PGR0=; h=From:To:Subject:Date:Message-Id; b=AaGMeLKFg85EpgA9/DfbfgB0NSk1B1lkNRbsOCUExSkGcN00c2U8vzeuS3DBtWdHZIFCE0h8OY6+gCjH2hczYzr4tdSLLv61MRNpbo2uuqObyyu72xYqBESd1v51V7uJazEOWVfd3B6OKnfFRJEfi5fNv5FC4DLcf0MqaAuqTlQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost.localdomain (unknown [10.12.130.31]) by app1 (Coremail) with SMTP id TAJkCgBHukZwWj9lI2cBAA--.13279S5; Mon, 30 Oct 2023 15:25:37 +0800 (CST) From: Fei Gao To: gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, palmer@dabbelt.com, jeffreyalaw@gmail.com, Fei Gao Subject: [PATCH 1/4] [RISC-V]add hook to control Zicond based ifcvt opt Date: Mon, 30 Oct 2023 07:25:20 +0000 Message-Id: <20231030072523.26818-2-gaofei@eswincomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231030072523.26818-1-gaofei@eswincomputing.com> References: <20231030072523.26818-1-gaofei@eswincomputing.com> X-CM-TRANSID: TAJkCgBHukZwWj9lI2cBAA--.13279S5 X-Coremail-Antispam: 1UD129KBjvJXoWxWw1ktrWftrW3Wr4fZr13Arb_yoW5tr45pa yUGr4Yvas5JFZ3Kw1ftr48G3W3Awn3GF1UCrs7JFWUAa17JrWkJF4qka4Sy3yDXFy5Zr43 ZrW09347uw4UCwUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUB214x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r1Y6r1xM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY02Avz4vE-syl42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6x kF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUONtxUUUUU X-CM-SenderInfo: xjdrwv3l6h245lqf0zpsxwx03jof0z/ X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLACK 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.30 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781164443547936324 X-GMAIL-MSGID: 1781164443547936324 TARGET_HAVE_COND_ZERO is added to control ifcvt optimization for targets with RISC-V Zicond like insns. Co-authored-by: Xiao Zeng gcc/ChangeLog: * config/riscv/riscv.cc (riscv_have_cond_zero): Implement TARGET_HAVE_COND_ZERO (TARGET_HAVE_COND_ZERO): define RISC-V hook * doc/tm.texi: add TARGET_HAVE_COND_ZERO * doc/tm.texi.in: add TARGET_HAVE_COND_ZERO * target.def: define TARGET_HAVE_COND_ZERO --- gcc/config/riscv/riscv.cc | 10 ++++++++++ gcc/doc/tm.texi | 4 ++++ gcc/doc/tm.texi.in | 2 ++ gcc/target.def | 7 +++++++ 4 files changed, 23 insertions(+) diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index ca9a2ca81d5..16a91713ba5 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -9597,6 +9597,13 @@ riscv_vectorize_create_costs (vec_info *vinfo, bool costing_for_scalar) return new vector_costs (vinfo, costing_for_scalar); } +/* Implement TARGET_HAVE_COND_ZERO. */ +bool +riscv_have_cond_zero (void) +{ + return TARGET_ZICOND_LIKE; +} + /* Implement TARGET_PREFERRED_ELSE_VALUE. */ static tree @@ -9884,6 +9891,9 @@ riscv_preferred_else_value (unsigned ifn, tree vectype, unsigned int nops, #undef TARGET_DWARF_POLY_INDETERMINATE_VALUE #define TARGET_DWARF_POLY_INDETERMINATE_VALUE riscv_dwarf_poly_indeterminate_value +#undef TARGET_HAVE_COND_ZERO +#define TARGET_HAVE_COND_ZERO riscv_have_cond_zero + #undef TARGET_ZERO_CALL_USED_REGS #define TARGET_ZERO_CALL_USED_REGS riscv_zero_call_used_regs diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index f7ac806ff15..fe4f59d445e 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -12080,6 +12080,10 @@ This target hook is required only when the target has several different modes and they have different conditional execution capability, such as ARM. @end deftypefn +@deftypefn {Target Hook} bool TARGET_HAVE_COND_ZERO (void) +This target hook returns true if the target supports conditional zero. +@end deftypefn + @deftypefn {Target Hook} rtx TARGET_GEN_CCMP_FIRST (rtx_insn **@var{prep_seq}, rtx_insn **@var{gen_seq}, rtx_code @var{code}, tree @var{op0}, tree @var{op1}) This function prepares to emit a comparison insn for the first compare in a sequence of conditional comparisions. It returns an appropriate comparison diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index 141027e0bb4..12aadd75a13 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -7832,6 +7832,8 @@ lists. @hook TARGET_HAVE_CONDITIONAL_EXECUTION +@hook TARGET_HAVE_COND_ZERO + @hook TARGET_GEN_CCMP_FIRST @hook TARGET_GEN_CCMP_NEXT diff --git a/gcc/target.def b/gcc/target.def index 42622177ef9..f977edc3430 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -2726,6 +2726,13 @@ modes and they have different conditional execution capability, such as ARM.", bool, (void), default_have_conditional_execution) +/* Return true if the target supports conditional zero. */ +DEFHOOK +(have_cond_zero, + "This target hook returns true if the target supports conditional zero.", + bool, (void), + hook_bool_void_false) + DEFHOOK (gen_ccmp_first, "This function prepares to emit a comparison insn for the first compare in a\n\ From patchwork Mon Oct 30 07:25:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fei Gao X-Patchwork-Id: 159540 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp2034679vqb; Mon, 30 Oct 2023 00:26:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGvW0lbAhOD4A4xdPaW9dIgC1fQ6U+LVlEjfHdR19MHNeOMO5MjXKe0PGVf81p9NvMlxOX1 X-Received: by 2002:a05:622a:453:b0:418:cec:5e64 with SMTP id o19-20020a05622a045300b004180cec5e64mr19163090qtx.19.1698650786816; Mon, 30 Oct 2023 00:26:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698650786; cv=pass; d=google.com; s=arc-20160816; b=ASxhngT4duXSDzGmOjZ5hy+ElZ+E+vgy735g+ySUGjDdpJ3D3HBY9CvTnO96ydCUNK xwLvIhYuMYdOqn1Z1P2nmZqYPQ29FylrQgV1FOEC9Q8gCJF7emDC3zQyqNlSOVK+sPGY aSfx/tO7Agh5mULZsoPldkb0UdfMQ5SdE1ZkS0a4kNXPtqepmPzo4z0ZHqp4ELSQo+Qg AaqFw+83XZ0v8p6BXgTH5JCsUG0cXE9JauDf84BHPzE3id9qHw56g2PxZl5aG9Sx/0Wc U1eIdIFJNDEWBziGAn74wOEAlu3H3wffArsTjvlMiPnEf1vGRo/If8sUXxo7RuuAg6Qj UNvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:cc:to:from:arc-filter:dmarc-filter :delivered-to; bh=SSrzmpJYDvzSLFBnOVTSQMdy4GGKGUowbl/XahUPTFU=; fh=dfjB68vu7iz5i8RrpOG22UZ7WIvYTHhHfK87YX5Okjc=; b=K/pVcKFpzgxmUABiTpZ9wrTF00wQdvSgNZmcOgifWinhdupotgvi1R2eiyhrm8MkLh ZFSZlsJBNx1fArc/bUrH3njQSlYkpf9oY7cywgJm9c3Apfd/OD39uOk4u1jnpLopBwKb 8tFpQ6ReUrw9tZfstps0vVteKrDC9VVfs7YtRYTuoQVlO1ZOcfawKtInHfqZLS2yzAJS m/HuAgjMxvMVrMX8rcrpv8fnScJ3V0oC68u+NNXqlvfYpQYOH0Gj7gV5SSL9+gI6iefL LSAOPWYQB6OpT2Gm+TLebUFWSSKrQfunETfF3fxSOGF4TAQNwjzOKqj9hDy74h9IL+fE 0mVg== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id c4-20020ac87dc4000000b0041cbbbc2ed1si5218324qte.362.2023.10.30.00.26.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 00:26:26 -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; arc=pass (i=1); 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 DCE663858C36 for ; Mon, 30 Oct 2023 07:26:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from zg8tndyumtaxlji0oc4xnzya.icoremail.net (zg8tndyumtaxlji0oc4xnzya.icoremail.net [46.101.248.176]) by sourceware.org (Postfix) with ESMTP id 59A553858D33 for ; Mon, 30 Oct 2023 07:25:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 59A553858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=eswincomputing.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=eswincomputing.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 59A553858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=46.101.248.176 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698650756; cv=none; b=d0oBTzkDftxG25w/YXDKpm8GM/Xd0AKPd56fkIiLlfLH6/0CdJNCA8XZgZvTN0Ky9g8NNl25V2t0+vXZ5M7LffXzIsH9asuHHO+42O1JWF8zUS9GBEDIy7bYT4EYydmmcwfkFb4O82XMZFmiagN0cRoITDvu4iGQNBc9BsuQ0w4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698650756; c=relaxed/simple; bh=fjzh37cZLB2+xVV4CxAIKo0qcMw3McZmbiXoREr7NIs=; h=From:To:Subject:Date:Message-Id; b=uF3ytrZz7/O9nuj5q/aatGpeWizlM1kCekqKfHR89h34HXD4/6grI9eNr7jR6MvoDaIYJRBfyHMqO34EF1aqjjn5nqjxM3dfhsUM6oeLBfm00HL/0L7nTLwq8aAG0JhasLPt8Kl9G37eJT8EqNP34EAA/3ex5NfP2T8J/NdcpA8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost.localdomain (unknown [10.12.130.31]) by app1 (Coremail) with SMTP id TAJkCgBHukZwWj9lI2cBAA--.13279S6; Mon, 30 Oct 2023 15:25:39 +0800 (CST) From: Fei Gao To: gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, palmer@dabbelt.com, jeffreyalaw@gmail.com, Fei Gao Subject: [PATCH 2/4] [ifcvt] if convert x=c ? y+z : y by RISC-V Zicond like insns Date: Mon, 30 Oct 2023 07:25:21 +0000 Message-Id: <20231030072523.26818-3-gaofei@eswincomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231030072523.26818-1-gaofei@eswincomputing.com> References: <20231030072523.26818-1-gaofei@eswincomputing.com> X-CM-TRANSID: TAJkCgBHukZwWj9lI2cBAA--.13279S6 X-Coremail-Antispam: 1UD129KBjvJXoW3GF18tFWkJF17ArW5tF1fWFg_yoW3Jw1kpF W3Gry3KF4fAFWfGF48JFW5J3Wakr1SgryUW3s7A3yfAws5XrZYkFy8K3WF9rnxJayrWr1a 9a1jyr4qgF17JrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUB214x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26r1I6r4UM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY02Avz4vE-syl42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6x kF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfU5wIDUUUUU X-CM-SenderInfo: xjdrwv3l6h245lqf0zpsxwx03jof0z/ X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, LIKELY_SPAM_BODY, RCVD_IN_MSPIKE_H2, 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.30 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781164447168958817 X-GMAIL-MSGID: 1781164447168958817 Conditional add, if zero rd = (rc == 0) ? (rs1 + rs2) : rs1 --> czero.nez rd, rs2, rc add rd, rs1, rd Conditional add, if non-zero rd = (rc != 0) ? (rs1 + rs2) : rs1 --> czero.eqz rd, rs2, rc add rd, rs1, rd Co-authored-by: Xiao Zeng gcc/ChangeLog: * ifcvt.cc (noce_emit_czero): helper for noce_try_cond_zero_arith (noce_try_cond_zero_arith): handler for condtional zero op (noce_process_if_block): add noce_try_cond_zero_arith with hook control gcc/testsuite/ChangeLog: * gcc.target/riscv/zicond_ifcvt_opt.c: New test. --- gcc/ifcvt.cc | 112 +++++++++++++++ .../gcc.target/riscv/zicond_ifcvt_opt.c | 130 ++++++++++++++++++ 2 files changed, 242 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/zicond_ifcvt_opt.c diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc index a0af553b9ff..4f98c1c7bf9 100644 --- a/gcc/ifcvt.cc +++ b/gcc/ifcvt.cc @@ -781,12 +781,14 @@ static bool noce_try_store_flag_constants (struct noce_if_info *); static bool noce_try_store_flag_mask (struct noce_if_info *); static rtx noce_emit_cmove (struct noce_if_info *, rtx, enum rtx_code, rtx, rtx, rtx, rtx, rtx = NULL, rtx = NULL); +static rtx noce_emit_czero (struct noce_if_info *, enum rtx_code, rtx, rtx); static bool noce_try_cmove (struct noce_if_info *); static bool noce_try_cmove_arith (struct noce_if_info *); static rtx noce_get_alt_condition (struct noce_if_info *, rtx, rtx_insn **); static bool noce_try_minmax (struct noce_if_info *); static bool noce_try_abs (struct noce_if_info *); static bool noce_try_sign_mask (struct noce_if_info *); +static bool noce_try_cond_zero_arith (struct noce_if_info *); /* Return the comparison code for reversed condition for IF_INFO, or UNKNOWN if reversing the condition is not possible. */ @@ -1831,6 +1833,32 @@ noce_emit_cmove (struct noce_if_info *if_info, rtx x, enum rtx_code code, return NULL_RTX; } +static rtx +noce_emit_czero (struct noce_if_info *if_info, enum rtx_code czero_code, rtx z, rtx target) +{ + machine_mode mode = GET_MODE (target); + rtx cond_op0 = XEXP (if_info->cond, 0); + rtx czero_cond + = gen_rtx_fmt_ee (czero_code, GET_MODE (cond_op0), cond_op0, const0_rtx); + rtx if_then_else = gen_rtx_IF_THEN_ELSE (mode, czero_cond, const0_rtx, z); + rtx set = gen_rtx_SET (target, if_then_else); + + start_sequence (); + rtx_insn *insn = emit_insn (set); + + if (recog_memoized (insn) >= 0) + { + rtx_insn *seq = get_insns (); + end_sequence (); + emit_insn (seq); + + return target; + } + + end_sequence (); + return NULL_RTX; +} + /* Try only simple constants and registers here. More complex cases are handled in noce_try_cmove_arith after noce_try_store_flag_arith has had a go at it. */ @@ -2880,6 +2908,88 @@ noce_try_sign_mask (struct noce_if_info *if_info) return true; } +/* Convert x = c ? y + z : y or x = c ? y : y + z. */ + +static bool +noce_try_cond_zero_arith (struct noce_if_info *if_info) +{ + rtx target; + rtx_insn *seq; + machine_mode mode = GET_MODE (if_info->x); + rtx common = NULL_RTX; + enum rtx_code czero_code = UNKNOWN; + rtx a = if_info->a; + rtx b = if_info->b; + rtx z = NULL_RTX; + rtx cond = if_info->cond; + + if (!noce_simple_bbs (if_info)) + return false; + + /* cond must be EQ or NEQ comparision of a reg and 0. */ + if (GET_CODE (cond) != NE && GET_CODE (cond) != EQ) + return false; + if (!REG_P (XEXP (cond, 0)) || !rtx_equal_p (XEXP (cond, 1), const0_rtx)) + return false; + + /* check y + z:y*/ + if (GET_CODE (a) == PLUS && REG_P (XEXP (a, 0)) && REG_P (XEXP (a, 1)) + && REG_P (b) && rtx_equal_p (XEXP (a, 0), b)) + { + common = b; + z = XEXP (a, 1); + /* x = c ? y+z : y, cond = !c --> x = cond ? y : y+z */ + czero_code = GET_CODE (cond); + } + /* check y : y+z */ + else if (GET_CODE (b) == PLUS && REG_P (XEXP (b, 0)) && REG_P (XEXP (b, 1)) + && REG_P (a) && rtx_equal_p (a, XEXP (b, 0))) + { + common = a; + z = XEXP (b, 1); + /* x = c ? y : y+z, cond = !c --> x = !cond ? y : y+z */ + czero_code = noce_reversed_cond_code (if_info); + } + else + return false; + + if (czero_code == UNKNOWN) + return false; + + start_sequence (); + + /* If we have x = c ? x + z : x, use a new reg to avoid modifying x */ + if (common && rtx_equal_p (common, if_info->x)) + target = gen_reg_rtx (mode); + else + target = if_info->x; + + target = noce_emit_czero (if_info, czero_code, z, target); + if (!target) + { + end_sequence (); + return false; + } + + target = expand_simple_binop (mode, PLUS, common, target, if_info->x, 0, + OPTAB_DIRECT); + if (!target) + { + end_sequence (); + return false; + } + + if (target != if_info->x) + noce_emit_move_insn (if_info->x, target); + + seq = end_ifcvt_sequence (if_info); + if (!seq || !targetm.noce_conversion_profitable_p (seq, if_info)) + return false; + + emit_insn_before_setloc (seq, if_info->jump, INSN_LOCATION (if_info->insn_a)); + if_info->transform_name = "noce_try_cond_zero_arith"; + return true; +} /* Optimize away "if (x & C) x |= C" and similar bit manipulation transformations. */ @@ -3975,6 +4085,8 @@ noce_process_if_block (struct noce_if_info *if_info) goto success; if (noce_try_store_flag_mask (if_info)) goto success; + if (targetm.have_cond_zero () && noce_try_cond_zero_arith (if_info)) + goto success; if (HAVE_conditional_move && noce_try_cmove_arith (if_info)) goto success; diff --git a/gcc/testsuite/gcc.target/riscv/zicond_ifcvt_opt.c b/gcc/testsuite/gcc.target/riscv/zicond_ifcvt_opt.c new file mode 100644 index 00000000000..068c1443413 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zicond_ifcvt_opt.c @@ -0,0 +1,130 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc_zicond -mabi=lp64d -O2" } */ +/* { dg-skip-if "" { *-*-* } {"-O0" "-O1" "-Os" "-Og" "-O3" "-Oz" "-flto"} } */ +/* { dg-final { check-function-bodies "**" "" } } */ + +/* +**test_ADD_ceqz: +** czero\.eqz a3,a2,a3 +** add a0,a1,a3 +** ret +*/ +// x = c ? y+z : y +long test_ADD_ceqz(long x, long y, long z, long c) +{ + if (c) + x = y + z; + else + x = y; + return x; +} + +/* +**test_ADD_ceqz_x: +** czero\.eqz a2,a1,a2 +** add a0,a0,a2 +** ret +*/ +// x = c ? x+z : x +long test_ADD_ceqz_x(long x, long z, long c) +{ + if (c) + x = x + z; + + return x; +} + +/* +**test_ADD_nez: +** czero\.nez a3,a2,a3 +** add a0,a1,a3 +** ret +*/ +// x = c ? y : y+z +long test_ADD_nez(long x, long y, long z, long c) +{ + if (c) + x = y; + else + x = y + z; + return x; +} + +/* +**test_ADD_nez_x: +** czero\.nez a2,a1,a2 +** add a0,a0,a2 +** ret +*/ +// x = c ? x : x+z +long test_ADD_nez_x(long x, long z, long c) +{ + if (c) + {} + else + x = x + z; + return x; +} + +/* +**test_ADD_nez_2: +** czero\.nez a3,a2,a3 +** add a0,a1,a3 +** ret +*/ +// x = !c ? y+z : y +long test_ADD_nez_2(long x, long y, long z, long c) +{ + if (!c) + x = y + z; + else + x = y; + return x; +} + +/* +**test_ADD_nez_x_2: +** czero\.nez a2,a1,a2 +** add a0,a0,a2 +** ret +*/ +// x = !c ? x+z : x +long test_ADD_nez_x_2(long x, long z, long c) +{ + if (!c) + x = x + z; + + return x; +} + +/* +**test_ADD_eqz_2: +** czero\.eqz a3,a2,a3 +** add a0,a1,a3 +** ret +*/ +// x = !c ? y : y+z +long test_ADD_eqz_2(long x, long y, long z, long c) +{ + if (!c) + x = y; + else + x = y + z; + return x; +} + +/* +**test_ADD_eqz_x_2: +** czero\.eqz a2,a1,a2 +** add a0,a0,a2 +** ret +*/ +// x = !c ? x : x+z +long test_ADD_eqz_x_2(long x, long z, long c) +{ + if (!c) + {} + else + x = x + z; + return x; +} From patchwork Mon Oct 30 07:25:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fei Gao X-Patchwork-Id: 159545 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp2035034vqb; Mon, 30 Oct 2023 00:27:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFjzj7VUS+zVR8atcuMWNfs2/9o6y9p5RyYeIz3PBjKhOaZADqWapOxWY2VvayfuSANWqD0 X-Received: by 2002:a05:620a:f10:b0:774:20f2:cb86 with SMTP id v16-20020a05620a0f1000b0077420f2cb86mr9261872qkl.49.1698650848306; Mon, 30 Oct 2023 00:27:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698650848; cv=pass; d=google.com; s=arc-20160816; b=0xSffoLBgWe0dMCtsp56L+CUfl2BftCk4hJKzIWyOlGt7VaZBNp5q7HoBpAw+09dta 3ONb3pV4sPzG8ro4ecIcSg9Y5KZ+khf/9drtVw9bmBsglyriux4pvNcPA3MT/zsbOFCp FqU3Xbbng6Ois+R8miAUdgzzYwMxwssPboxuvejUNVZa2ld9VbE+Wcr5SQBnNDSVUhdv IurJhBMPMs1HDH80pSFUvlxWSDqoW/bCCO07JmmSnJlcs7WIqVAdsXdMOo3Y+w5ew2mR S9hAuZyvlCfr9tNFwPelcYgZEoykS568CKEw2fPB3qpQUDP6l/VNTqnuhBaeNYZCydQG 1phg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:cc:to:from:arc-filter:dmarc-filter :delivered-to; bh=q8drOMfBcyCw/RR0o2IVyjZ61JcPhU3gYYd+52a/HB4=; fh=dfjB68vu7iz5i8RrpOG22UZ7WIvYTHhHfK87YX5Okjc=; b=ynozfhih+PYxObQzAFV9u3r6v3QOk150qLskMxA0flI8tClNGdH9kPGe9GficTfA5o OPGOWIFYvQvrREVEn06hOrjt8TKrvOqGqO/gTEdbqcph2rOTMG9pnTEoGahf0ymMiJtf R1FzzZLmTHhQRZcYGE3Iq77fyqg9MUwLJM5rAqmvTVN0HG3a6S/0k3YwDtmM5rZ7ZnnY LekeRYMUyKXUEzyRuhm5VNQkvynOFz1wK0Z90oZlekO/c9Myl2nK4D36pDFD8SIZS4k5 S0SZofrqBu5PSovVDi7aIf5zau6xnxpu1aBlexAS6mkLfuG9ngXwqgygCUStRFAolsz+ wIkw== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id vq18-20020a05620a559200b0077a02af4d3bsi4998831qkn.580.2023.10.30.00.27.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 00:27:28 -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; arc=pass (i=1); 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 132A13858C36 for ; Mon, 30 Oct 2023 07:27:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from zg8tmja2lje4os4yms4ymjma.icoremail.net (zg8tmja2lje4os4yms4ymjma.icoremail.net [206.189.21.223]) by sourceware.org (Postfix) with ESMTP id E242938582BC for ; Mon, 30 Oct 2023 07:26:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E242938582BC Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=eswincomputing.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=eswincomputing.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E242938582BC Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=206.189.21.223 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698650812; cv=none; b=OTdlkaw4mJbZ1FcrkrX2fs+QA/aSqRWQ+BjFo6Br9dZ56B/j5bvo063b3pSlA7R6fvGxy/UdFRjZZUhYmvZ7O+ekabCEwwrhI03TGevAlSQL4wthiKfKgc2n3f6Wn7DVaaqWVa/tWupriVvGBPL0CYvcWrJHJmQAGKe+goYLnhI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698650812; c=relaxed/simple; bh=i3EDoaxr0rSuQLMBd9SpeyrbYLKnUrxd3xdlkgqXdl0=; h=From:To:Subject:Date:Message-Id; b=JJA/72YWyNKOofO0IKWd9N51QQZy45QYe59Gpkb2/n1d6A/YWK407Lf6hUOBsXLNkDnVFM4Q0vwDhCgceiOgeUh39/kPiRDBaTidlk6cEAhcorqnGDL+xQmnQudmW/NqH2op5+QATIK4gBK/FRQE5QLD5ZTvhbm1kfoanBWliDo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost.localdomain (unknown [10.12.130.31]) by app1 (Coremail) with SMTP id TAJkCgBHukZwWj9lI2cBAA--.13279S7; Mon, 30 Oct 2023 15:25:40 +0800 (CST) From: Fei Gao To: gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, palmer@dabbelt.com, jeffreyalaw@gmail.com, Fei Gao Subject: [PATCH 3/4] [ifcvt] if convert x=c ? y op z : y by RISC-V Zicond like insns Date: Mon, 30 Oct 2023 07:25:22 +0000 Message-Id: <20231030072523.26818-4-gaofei@eswincomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231030072523.26818-1-gaofei@eswincomputing.com> References: <20231030072523.26818-1-gaofei@eswincomputing.com> X-CM-TRANSID: TAJkCgBHukZwWj9lI2cBAA--.13279S7 X-Coremail-Antispam: 1UD129KBjvJXoWxtF18JF4kCFyrWr4ruw45Jrb_yoW3GFWUpF Waq3sFyr4fAFyfGF48JrZ8Z3ZYkr1Sqry8GrZayrW5urn3XrZayw4Fy3W2vrnrAFs3Wr13 Ca4UtrWqvFW7J3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUB214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JrWl82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY02Avz4vE-syl42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6x kF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfU8tx6UUUUU X-CM-SenderInfo: xjdrwv3l6h245lqf0zpsxwx03jof0z/ X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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.30 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781164512042903604 X-GMAIL-MSGID: 1781164512042903604 op=[-, |, ^] opcode=[sub, or, xor] Conditional op, if zero rd = (rc == 0) ? (rs1 op rs2) : rs1 --> czero.nez rd, rs2, rc opcode rd, rs1, rd Conditional op, if non-zero rd = (rc != 0) ? (rs1 op rs2) : rs1 --> czero.eqz rd, rs2, rc opcode rd, rs1, rd Co-authored-by: Xiao Zeng gcc/ChangeLog: * ifcvt.cc (noce_cond_zero_binary_op_supported): add more op=[-, |, ^] (noce_try_cond_zero_arith): adapt for newly added op gcc/testsuite/ChangeLog: * gcc.target/riscv/zicond_ifcvt_opt.c: add TCs for op=[-, |, ^] --- gcc/ifcvt.cc | 23 +- .../gcc.target/riscv/zicond_ifcvt_opt.c | 378 ++++++++++++++++++ 2 files changed, 396 insertions(+), 5 deletions(-) diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc index 4f98c1c7bf9..6e341fc4d4b 100644 --- a/gcc/ifcvt.cc +++ b/gcc/ifcvt.cc @@ -2908,6 +2908,15 @@ noce_try_sign_mask (struct noce_if_info *if_info) return true; } +static bool +noce_cond_zero_binary_op_supported (enum rtx_code op) +{ + if (op == PLUS || op == MINUS || op == IOR || op == XOR) + return true; + + return false; +} + /* Convert x = c ? y + z : y or x = c ? y : y + z. */ static bool @@ -2918,6 +2927,7 @@ noce_try_cond_zero_arith (struct noce_if_info *if_info) machine_mode mode = GET_MODE (if_info->x); rtx common = NULL_RTX; enum rtx_code czero_code = UNKNOWN; + enum rtx_code opcode = UNKNOWN; rtx a = if_info->a; rtx b = if_info->b; rtx z = NULL_RTX; @@ -2933,18 +2943,21 @@ noce_try_cond_zero_arith (struct noce_if_info *if_info) return false; /* check y + z:y*/ - if (GET_CODE (a) == PLUS && REG_P (XEXP (a, 0)) && REG_P (XEXP (a, 1)) - && REG_P (b) && rtx_equal_p (XEXP (a, 0), b)) + if (noce_cond_zero_binary_op_supported (GET_CODE (a)) && REG_P (XEXP (a, 0)) + && REG_P (XEXP (a, 1)) && REG_P (b) && rtx_equal_p (XEXP (a, 0), b)) { + opcode = GET_CODE (a); common = b; z = XEXP (a, 1); /* x = c ? y+z : y, cond = !c --> x = cond ? y : y+z */ czero_code = GET_CODE (cond); } /* check y : y+z */ - else if (GET_CODE (b) == PLUS && REG_P (XEXP (b, 0)) && REG_P (XEXP (b, 1)) - && REG_P (a) && rtx_equal_p (a, XEXP (b, 0))) + else if (noce_cond_zero_binary_op_supported (GET_CODE (b)) + && REG_P (XEXP (b, 0)) && REG_P (XEXP (b, 1)) && REG_P (a) + && rtx_equal_p (a, XEXP (b, 0))) { + opcode = GET_CODE (b); common = a; z = XEXP (b, 1); /* x = c ? y : y+z, cond = !c --> x = !cond ? y : y+z */ @@ -2971,7 +2984,7 @@ noce_try_cond_zero_arith (struct noce_if_info *if_info) return false; } - target = expand_simple_binop (mode, PLUS, common, target, if_info->x, 0, + target = expand_simple_binop (mode, opcode, common, target, if_info->x, 0, OPTAB_DIRECT); if (!target) { diff --git a/gcc/testsuite/gcc.target/riscv/zicond_ifcvt_opt.c b/gcc/testsuite/gcc.target/riscv/zicond_ifcvt_opt.c index 068c1443413..3ec01dcb135 100644 --- a/gcc/testsuite/gcc.target/riscv/zicond_ifcvt_opt.c +++ b/gcc/testsuite/gcc.target/riscv/zicond_ifcvt_opt.c @@ -128,3 +128,381 @@ long test_ADD_eqz_x_2(long x, long z, long c) x = x + z; return x; } + +/* +**test_SUB_ceqz: +** czero\.eqz a3,a2,a3 +** sub a0,a1,a3 +** ret +*/ +// x = c ? y-z : y +long test_SUB_ceqz(long x, long y, long z, long c) +{ + if (c) + x = y - z; + else + x = y; + return x; +} + +/* +**test_SUB_ceqz_x: +** czero\.eqz a2,a1,a2 +** sub a0,a0,a2 +** ret +*/ +// x = c ? x-z : x +long test_SUB_ceqz_x(long x, long z, long c) +{ + if (c) + x = x - z; + + return x; +} + +/* +**test_SUB_nez: +** czero\.nez a3,a2,a3 +** sub a0,a1,a3 +** ret +*/ +// x = c ? y : y-z +long test_SUB_nez(long x, long y, long z, long c) +{ + if (c) + x = y; + else + x = y - z; + return x; +} + +/* +**test_SUB_nez_x: +** czero\.nez a2,a1,a2 +** sub a0,a0,a2 +** ret +*/ +// x = c ? x : x-z +long test_SUB_nez_x(long x, long z, long c) +{ + if (c) + {} + else + x = x - z; + return x; +} + +/* +**test_SUB_nez_2: +** czero\.nez a3,a2,a3 +** sub a0,a1,a3 +** ret +*/ +// x = !c ? y-z : y +long test_SUB_nez_2(long x, long y, long z, long c) +{ + if (!c) + x = y - z; + else + x = y; + return x; +} + +/* +**test_SUB_nez_x_2: +** czero\.nez a2,a1,a2 +** sub a0,a0,a2 +** ret +*/ +// x = !c ? x-z : x +long test_SUB_nez_x_2(long x, long z, long c) +{ + if (!c) + x = x - z; + + return x; +} + +/* +**test_SUB_eqz_2: +** czero\.eqz a3,a2,a3 +** sub a0,a1,a3 +** ret +*/ +// x = !c ? y : y-z +long test_SUB_eqz_2(long x, long y, long z, long c) +{ + if (!c) + x = y; + else + x = y - z; + return x; +} + +/* +**test_SUB_eqz_x_2: +** czero\.eqz a2,a1,a2 +** sub a0,a0,a2 +** ret +*/ +// x = !c ? x : x-z +long test_SUB_eqz_x_2(long x, long z, long c) +{ + if (!c) + {} + else + x = x - z; + return x; +} + +/* +**test_IOR_ceqz: +** czero\.eqz a3,a2,a3 +** or a0,a1,a3 +** ret +*/ +// x = c ? y|z : y +long test_IOR_ceqz(long x, long y, long z, long c) +{ + if (c) + x = y | z; + else + x = y; + return x; +} + +/* +**test_IOR_ceqz_x: +** czero\.eqz a2,a1,a2 +** or a0,a0,a2 +** ret +*/ +// x = c ? x|z : x +long test_IOR_ceqz_x(long x, long z, long c) +{ + if (c) + x = x | z; + + return x; +} + +/* +**test_IOR_nez: +** czero\.nez a3,a2,a3 +** or a0,a1,a3 +** ret +*/ +// x = c ? y : y|z +long test_IOR_nez(long x, long y, long z, long c) +{ + if (c) + x = y; + else + x = y | z; + return x; +} + +/* +**test_IOR_nez_x: +** czero\.nez a2,a1,a2 +** or a0,a0,a2 +** ret +*/ +// x = c ? x : x|z +long test_IOR_nez_x(long x, long z, long c) +{ + if (c) + {} + else + x = x | z; + return x; +} + +/* +**test_IOR_nez_2: +** czero\.nez a3,a2,a3 +** or a0,a1,a3 +** ret +*/ +// x = !c ? y|z : y +long test_IOR_nez_2(long x, long y, long z, long c) +{ + if (!c) + x = y | z; + else + x = y; + return x; +} + +/* +**test_IOR_nez_x_2: +** czero\.nez a2,a1,a2 +** or a0,a0,a2 +** ret +*/ +// x = !c ? x|z : x +long test_IOR_nez_x_2(long x, long z, long c) +{ + if (!c) + x = x | z; + + return x; +} + +/* +**test_IOR_eqz_2: +** czero\.eqz a3,a2,a3 +** or a0,a1,a3 +** ret +*/ +// x = !c ? y : y|z +long test_IOR_eqz_2(long x, long y, long z, long c) +{ + if (!c) + x = y; + else + x = y | z; + return x; +} + +/* +**test_IOR_eqz_x_2: +** czero\.eqz a2,a1,a2 +** or a0,a0,a2 +** ret +*/ +// x = !c ? x : x|z +long test_IOR_eqz_x_2(long x, long z, long c) +{ + if (!c) + {} + else + x = x | z; + return x; +} + +/* +**test_XOR_ceqz: +** czero\.eqz a3,a2,a3 +** xor a0,a1,a3 +** ret +*/ +// x = c ? y^z : y +long test_XOR_ceqz(long x, long y, long z, long c) +{ + if (c) + x = y ^ z; + else + x = y; + return x; +} + +/* +**test_XOR_ceqz_x: +** czero\.eqz a2,a1,a2 +** xor a0,a0,a2 +** ret +*/ +// x = c ? x^z : x +long test_XOR_ceqz_x(long x, long z, long c) +{ + if (c) + x = x ^ z; + + return x; +} + +/* +**test_XOR_nez: +** czero\.nez a3,a2,a3 +** xor a0,a1,a3 +** ret +*/ +// x = c ? y : y^z +long test_XOR_nez(long x, long y, long z, long c) +{ + if (c) + x = y; + else + x = y ^ z; + return x; +} + +/* +**test_XOR_nez_x: +** czero\.nez a2,a1,a2 +** xor a0,a0,a2 +** ret +*/ +// x = c ? x : x^z +long test_XOR_nez_x(long x, long z, long c) +{ + if (c) + {} + else + x = x ^ z; + return x; +} + +/* +**test_XOR_nez_2: +** czero\.nez a3,a2,a3 +** xor a0,a1,a3 +** ret +*/ +// x = !c ? y^z : y +long test_XOR_nez_2(long x, long y, long z, long c) +{ + if (!c) + x = y ^ z; + else + x = y; + return x; +} + +/* +**test_XOR_nez_x_2: +** czero\.nez a2,a1,a2 +** xor a0,a0,a2 +** ret +*/ +// x = !c ? x^z : x +long test_XOR_nez_x_2(long x, long z, long c) +{ + if (!c) + x = x ^ z; + + return x; +} + +/* +**test_XOR_eqz_2: +** czero\.eqz a3,a2,a3 +** xor a0,a1,a3 +** ret +*/ +// x = !c ? y : y^z +long test_XOR_eqz_2(long x, long y, long z, long c) +{ + if (!c) + x = y; + else + x = y ^ z; + return x; +} + +/* +**test_XOR_eqz_x_2: +** czero\.eqz a2,a1,a2 +** xor a0,a0,a2 +** ret +*/ +// x = !c ? x : x^z +long test_XOR_eqz_x_2(long x, long z, long c) +{ + if (!c) + {} + else + x = x ^ z; + return x; +} From patchwork Mon Oct 30 07:25:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fei Gao X-Patchwork-Id: 159544 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp2034867vqb; Mon, 30 Oct 2023 00:26:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH367su0pIxWqPWGmz9LHje+s7BHUJ0XVnhpDwo305HKxmhZASILxP9v0LJVJc4ITpwzInr X-Received: by 2002:a05:6808:23d3:b0:3af:9848:1590 with SMTP id bq19-20020a05680823d300b003af98481590mr10996471oib.6.1698650819617; Mon, 30 Oct 2023 00:26:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698650819; cv=pass; d=google.com; s=arc-20160816; b=tvzLSEIZ+yWr46Ek4ER+N+2REMGoLzRAkjHRwCbZRwMXUHxXE51ClHM7hgh7feEz6D 0afgrI76cJw0BB7yhHaRJ5mtx9zZY1gZd6PE8JqdvwRN+il8mWJ7vmP2tPhDIUPGPUld rVqObIqIDWB17lUexN66pNVfAU38GtCxXIIiLDr23RE7ghiG1iLZd9hcfp/wz0abo1S1 9BXN3IKFyXS5Tv4fGke79pYQjCmnerNcz2WMYoKw/qxR5vnTzOBXVD/pHu2GRf0RG7MQ /sQFs6I8hPIgNrliv9n6ZFTC8koJ7UL+Fi2W850KwOxu1x0pfk2q8zp6xFbIPr5BzHlg fP6w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:cc:to:from:arc-filter:dmarc-filter :delivered-to; bh=YqEX+44KoXn6mgYpntTkhEG92SYaCwvZWPXGwIHpm1I=; fh=dfjB68vu7iz5i8RrpOG22UZ7WIvYTHhHfK87YX5Okjc=; b=JVnvCbQdeXL7OHGxrgQ+XPpdJgkjKER/clE8OWXYQ8/AielZWwRpwyl9g3+j2tAI9v T06bYGTk3romQattl6O4ZnNRoPLUaZGka75BrfhyQLsG6eBBULAZS4aAaYgKsimmu+nA htOxsSG9+CGpzwApOTXWd4DBjQrVloAidTAYvMyU6fK2vq8K3N+Xtr/c3Mc3L1y+f0Mr jkzEbk+KH8ipV3pYnNKi8pDAmXuTThzbWfWdJBtJSVzQ8beYOYjiQehGoiFkwVSYG8Uk jST/Jla9tklzKnUzP/gIEqQH45nz9KYrHtzFXVnk8288h8O0xYiGAH/oeUhzCKdcOEJp H0Bg== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u20-20020a05620a455400b0076ef0da9545si5469986qkp.736.2023.10.30.00.26.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 00:26:59 -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; arc=pass (i=1); 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 478CB385841A for ; Mon, 30 Oct 2023 07:26:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from azure-sdnproxy.icoremail.net (azure-sdnproxy.icoremail.net [20.231.56.155]) by sourceware.org (Postfix) with ESMTP id 52C293858D35 for ; Mon, 30 Oct 2023 07:25:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 52C293858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=eswincomputing.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=eswincomputing.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 52C293858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=20.231.56.155 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698650756; cv=none; b=TONB7WAAj3tVpwlOZCqRQfq9OG1EEFR7h7QBWguUUXXre62Lwd20PtQuvPasQo/ZijNqx5ABeQo+7jI5nJXFU3sYlKS49bL1v3fSWEKrM5ZpDXkR4QMzzb7qz445hHhEdxklKBVmjVBOiQK9UvdreVHMVg/bsp6jbn09dpIRueA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698650756; c=relaxed/simple; bh=K+jqGXSmBkNMMrGXR9BCnHFcywlYjU83sGXA5S0Lu1E=; h=From:To:Subject:Date:Message-Id; b=l4PML9H2UGFP4/fcLbJ0vQotkzst7kdq2nCSo7M2T6TPAzUERU2s/2RIulZEntk8grAWEyBn6nbOQb7+4wShTs09aJ3kU0qQ5xAy/Oi6xsUE0ygkJEmMkrJeWbu62wgvP7Ytdojn0ShyDk5ZdhrS5F94IR5mf60QJtqvdTvV4TM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost.localdomain (unknown [10.12.130.31]) by app1 (Coremail) with SMTP id TAJkCgBHukZwWj9lI2cBAA--.13279S8; Mon, 30 Oct 2023 15:25:40 +0800 (CST) From: Fei Gao To: gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, palmer@dabbelt.com, jeffreyalaw@gmail.com, Fei Gao Subject: [PATCH 4/4] [ifcvt] if convert x=c ? y&z : y by RISC-V Zicond like insns Date: Mon, 30 Oct 2023 07:25:23 +0000 Message-Id: <20231030072523.26818-5-gaofei@eswincomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231030072523.26818-1-gaofei@eswincomputing.com> References: <20231030072523.26818-1-gaofei@eswincomputing.com> X-CM-TRANSID: TAJkCgBHukZwWj9lI2cBAA--.13279S8 X-Coremail-Antispam: 1UD129KBjvJXoW3JF1rAFykJFWUWFWDJFW3GFg_yoW7Zry7pF W3J347KrWfAFWfGF4rXFW3AFn0kr1rtryUWws3trZ3Cwn8ZrZYyr1rt3ZI9rnxJFWrWF1a 9ayUKFWqgF47J37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBS14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY02Avz4vE-syl42xK82 IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC2 0s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMI IF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF 0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87 Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfU8hL0UUUUU X-CM-SenderInfo: xjdrwv3l6h245lqf0zpsxwx03jof0z/ X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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.30 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781164482272097127 X-GMAIL-MSGID: 1781164482272097127 Conditional and, if zero rd = (rc == 0) ? (rs1 & rs2) : rs1 --> and rd, rs1, rs2 czero.eqz rtmp, rs1, rc or rd, rd, rtmp Conditional and, if non-zero rd = (rc != 0) ? (rs1 & rs2) : rs1 --> and rd, rs1, rs2 czero.nez rtmp, rs1, rc or rd, rd, rtmp Co-authored-by: Xiao Zeng gcc/ChangeLog: * ifcvt.cc (noce_cond_zero_binary_op_supported): add support for and (noce_try_cond_zero_arith): adapt for and operation. gcc/testsuite/ChangeLog: * gcc.target/riscv/zicond_ifcvt_opt.c: add TCs for and operation. --- gcc/ifcvt.cc | 60 +++++--- .../gcc.target/riscv/zicond_ifcvt_opt.c | 134 ++++++++++++++++++ 2 files changed, 176 insertions(+), 18 deletions(-) diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc index 6e341fc4d4b..cfa9bc4b850 100644 --- a/gcc/ifcvt.cc +++ b/gcc/ifcvt.cc @@ -2911,7 +2911,7 @@ noce_try_sign_mask (struct noce_if_info *if_info) static bool noce_cond_zero_binary_op_supported (enum rtx_code op) { - if (op == PLUS || op == MINUS || op == IOR || op == XOR) + if (op == PLUS || op == MINUS || op == IOR || op == XOR || op == AND) return true; return false; @@ -2922,7 +2922,7 @@ noce_cond_zero_binary_op_supported (enum rtx_code op) static bool noce_try_cond_zero_arith (struct noce_if_info *if_info) { - rtx target; + rtx target, tmp; rtx_insn *seq; machine_mode mode = GET_MODE (if_info->x); rtx common = NULL_RTX; @@ -2949,8 +2949,9 @@ noce_try_cond_zero_arith (struct noce_if_info *if_info) opcode = GET_CODE (a); common = b; z = XEXP (a, 1); - /* x = c ? y+z : y, cond = !c --> x = cond ? y : y+z */ - czero_code = GET_CODE (cond); + /* x = c ? y+z : y, cond = !c --> x = cond ? y : y+z, but AND differs */ + czero_code + = (opcode == AND) ? noce_reversed_cond_code (if_info) : GET_CODE (cond); } /* check y : y+z */ else if (noce_cond_zero_binary_op_supported (GET_CODE (b)) @@ -2960,8 +2961,9 @@ noce_try_cond_zero_arith (struct noce_if_info *if_info) opcode = GET_CODE (b); common = a; z = XEXP (b, 1); - /* x = c ? y : y+z, cond = !c --> x = !cond ? y : y+z */ - czero_code = noce_reversed_cond_code (if_info); + /* x = c ? y : y+z, cond = !c --> x = !cond ? y : y+z, but AND differs */ + czero_code + = (opcode == AND) ? GET_CODE (cond) : noce_reversed_cond_code (if_info); } else return false; @@ -2970,22 +2972,44 @@ noce_try_cond_zero_arith (struct noce_if_info *if_info) return false; start_sequence (); + if (opcode == AND) + { + tmp + = expand_simple_binop (mode, AND, common, z, NULL_RTX, 0, OPTAB_DIRECT); + if (!tmp) + { + end_sequence (); + return FALSE; + } - /* If we have x = c ? x + z : x, use a new reg to avoid modifying x */ - if (common && rtx_equal_p (common, if_info->x)) - target = gen_reg_rtx (mode); - else - target = if_info->x; + target = noce_emit_czero (if_info, czero_code, common, if_info->x); + if (!target) + { + end_sequence (); + return FALSE; + } - target = noce_emit_czero (if_info, czero_code, z, target); - if (!target) - { - end_sequence (); - return false; + target = expand_simple_binop (mode, IOR, tmp, target, if_info->x, 0, + OPTAB_DIRECT); } + else + { + /* If we have x = c ? x + z : x, use a new reg to avoid modifying x */ + if (common && rtx_equal_p (common, if_info->x)) + target = gen_reg_rtx (mode); + else + target = if_info->x; + + target = noce_emit_czero (if_info, czero_code, z, target); + if (!target) + { + end_sequence (); + return false; + } - target = expand_simple_binop (mode, opcode, common, target, if_info->x, 0, - OPTAB_DIRECT); + target = expand_simple_binop (mode, opcode, common, target, if_info->x, 0, + OPTAB_DIRECT); + } if (!target) { end_sequence (); diff --git a/gcc/testsuite/gcc.target/riscv/zicond_ifcvt_opt.c b/gcc/testsuite/gcc.target/riscv/zicond_ifcvt_opt.c index 3ec01dcb135..bfff570edd7 100644 --- a/gcc/testsuite/gcc.target/riscv/zicond_ifcvt_opt.c +++ b/gcc/testsuite/gcc.target/riscv/zicond_ifcvt_opt.c @@ -506,3 +506,137 @@ long test_XOR_eqz_x_2(long x, long z, long c) x = x ^ z; return x; } + +/* +**test_AND_ceqz: +** and a2,a1,a2 +** czero\.nez a1,a1,a3 +** or a0,a1,a2 +** ret +*/ +// x = c ? y&z : y +long test_AND_ceqz(long x, long y, long z, long c) +{ + if (c) + x = y & z; + else + x = y; + return x; +} + +/* +**test_AND_ceqz_x: +** and a1,a0,a1 +** czero\.nez a0,a0,a2 +** or a0,a0,a1 +** ret +*/ +// x = c ? x&z : x +long test_AND_ceqz_x(long x, long z, long c) +{ + if (c) + x = x & z; + + return x; +} + +/* +**test_AND_nez: +** and a2,a1,a2 +** czero\.eqz a1,a1,a3 +** or a0,a1,a2 +** ret +*/ +// x = c ? y : y&z +long test_AND_nez(long x, long y, long z, long c) +{ + if (c) + x = y; + else + x = y & z; + return x; +} + +/* +**test_AND_nez_x: +** and a1,a0,a1 +** czero\.eqz a0,a0,a2 +** or a0,a0,a1 +** ret +*/ +// x = c ? x : x&z +long test_AND_nez_x(long x, long z, long c) +{ + if (c) + {} + else + x = x & z; + return x; +} + +/* +**test_AND_nez_2: +** and a2,a1,a2 +** czero\.eqz a1,a1,a3 +** or a0,a1,a2 +** ret +*/ +// x = !c ? y&z : y +long test_AND_nez_2(long x, long y, long z, long c) +{ + if (!c) + x = y & z; + else + x = y; + return x; +} + +/* +**test_AND_nez_x_2: +** and a1,a0,a1 +** czero\.eqz a0,a0,a2 +** or a0,a0,a1 +** ret +*/ +// x = !c ? x&z : x +long test_AND_nez_x_2(long x, long z, long c) +{ + if (!c) + x = x & z; + + return x; +} + +/* +**test_AND_eqz_2: +** and a2,a1,a2 +** czero\.nez a1,a1,a3 +** or a0,a1,a2 +** ret +*/ +// x = !c ? y : y&z +long test_AND_eqz_2(long x, long y, long z, long c) +{ + if (!c) + x = y; + else + x = y & z; + return x; +} + +/* +**test_AND_eqz_x_2: +** and a1,a0,a1 +** czero\.nez a0,a0,a2 +** or a0,a0,a1 +** ret +*/ +// x = !c ? x : x&z +long test_AND_eqz_x_2(long x, long z, long c) +{ + if (!c) + {} + else + x = x & z; + return x; +}