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