From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 List-Id: 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; +} -- 2.17.1