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; +}