From patchwork Mon Jul 1 06:16:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kewen.Lin" X-Patchwork-Id: 1954733 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=HztlfAKh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WCSwS6bpsz1xpf for ; Tue, 2 Jul 2024 00:24:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2CA913810281 for ; Mon, 1 Jul 2024 14:24:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 9BA76381158C for ; Mon, 1 Jul 2024 14:22:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9BA76381158C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9BA76381158C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719843781; cv=none; b=CJDvLtVNbGMyldwghpo0byzFXvDAhqiXJK/QkXB5Ccz+LVcvqxOcvRQA6uukzoKAGRvuhWARPcufSTIvi5JXVF+PjssWkd0Bbh2BtWM38rDiEfkVk4tzrvZGxAIOeRooR7hmr3VqE7M7TIkrVQ/m2Bkx7aT9rM3DQpl8Cv4jP2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719843781; c=relaxed/simple; bh=TLxG43NlXTZJfRhfnO2Q3SfrbI8E7BjyY7vdRKJv5VY=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=aSMyugrxru7gsyLVdcFmO3YMxpeCsG9bRnCcyQcbH1qhE5H55CmV1Wcu8rIlrMR5BBJFzkUdsFmdZBLk3U2t4qRdGuBQWTuhb6SMAWD2hXz1yLJtoYk5XbSmbQfLf3YDq+w+F0u92RYvMfesef3FUACaBEs2U2uoWWzjM5DrBBE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0353722.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4615Qgb0024012; Mon, 1 Jul 2024 06:16:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h= message-id:date:mime-version:to:cc:from:subject:content-type :content-transfer-encoding; s=pp1; bh=7GakCN8z5N50jB07/a1vv1VM+m S0tGMLAIXWxPHn1+o=; b=HztlfAKh1INLe0y83EQ5YHMF/yaQhvL+XrTvSFXJ0z aDTp0f5M4HxMjfMiEQSv003/gkkH1Tjqk7xe8rSf67j2C01VQYBcaQZi95SmWkef Vld0No11dpQWyFnWO4PJDiVBaH3DNX9NFKXEhIiVjnjEsCiWtzZQkzk4QJrnVYRT 3IdkBDbVs8878E7rIBe7QOte/3RZdJJ0b2yqEJXU6gws2bPc85lwI8UKNwzWrZex I3qOndSlB/kFhvy7updyVvQZ8enjoVN1XjUSSLMoCDIZwN9G4Vuksafuj41eWUqj 2w2DHPjDGUfrJ9XEnAx4pUG1gOLLogjQOpWJcjkRYbmQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 403nfgr6s0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 01 Jul 2024 06:16:39 +0000 (GMT) Received: from m0353722.ppops.net (m0353722.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 4616GcnI003031; Mon, 1 Jul 2024 06:16:38 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 403nfgr6rt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 01 Jul 2024 06:16:38 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 4615GtYC009529; Mon, 1 Jul 2024 06:16:38 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 402xtmdg1u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 01 Jul 2024 06:16:37 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4616GYW533424112 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 1 Jul 2024 06:16:36 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4D83B20270; Mon, 1 Jul 2024 06:16:34 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0969B2026F; Mon, 1 Jul 2024 06:16:32 +0000 (GMT) Received: from [9.197.233.115] (unknown [9.197.233.115]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 1 Jul 2024 06:16:31 +0000 (GMT) Message-ID: <15f2301e-44b2-b29e-d3c5-7bcf6876da84@linux.ibm.com> Date: Mon, 1 Jul 2024 14:16:30 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Content-Language: en-US To: GCC Patches Cc: Richard Biener , Richard Sandiford , Segher Boessenkool , Peter Bergner , Andrew Pinski From: "Kewen.Lin" Subject: [PATCH] isel: Fold more in gimple_expand_vec_cond_expr [PR115659] X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: cYSPg4HNS9hYNmTR6qoF4B0YY_OFiyWV X-Proofpoint-GUID: wcVrVGnSyfK6p5jEJtKmW2UH97GDlGni X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-01_04,2024-06-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 mlxlogscore=909 mlxscore=0 impostorscore=0 phishscore=0 adultscore=0 spamscore=0 malwarescore=0 clxscore=1015 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2407010043 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, 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~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi, As PR115659 shows, assuming c = x CMP y, there are some folding chances for patterns r = c ? -1/z : z/0. For r = c ? -1 : z, it can be folded into: - r = c | z (with ior_optab supported) - or r = c ? c : z while for r = c ? z : 0, it can be foled into: - r = c & z (with and_optab supported) - or r = c ? z : c This patch is to teach ISEL to take care of them and also remove the redundant gsi_replace as the caller of function gimple_expand_vec_cond_expr will handle it. Bootstrapped and regtested on x86_64-redhat-linux and powerpc64{,le}-linux-gnu. Is it ok for trunk? BR, Kewen ----- PR tree-optimization/115659 gcc/ChangeLog: * gimple-isel.cc (gimple_expand_vec_cond_expr): Add more foldings for patterns x CMP y ? -1 : z and x CMP y ? z : 0. --- gcc/gimple-isel.cc | 48 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) -- 2.43.0 diff --git a/gcc/gimple-isel.cc b/gcc/gimple-isel.cc index 54c1801038b..71af1a8cd97 100644 --- a/gcc/gimple-isel.cc +++ b/gcc/gimple-isel.cc @@ -240,16 +240,50 @@ gimple_expand_vec_cond_expr (struct function *fun, gimple_stmt_iterator *gsi, can_compute_op0 = expand_vec_cmp_expr_p (op0a_type, op0_type, tcode); - /* Try to fold x CMP y ? -1 : 0 to x CMP y. */ if (can_compute_op0 - && integer_minus_onep (op1) - && integer_zerop (op2) && TYPE_MODE (TREE_TYPE (lhs)) == TYPE_MODE (TREE_TYPE (op0))) { - tree conv_op = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (lhs), op0); - gassign *new_stmt = gimple_build_assign (lhs, conv_op); - gsi_replace (gsi, new_stmt, true); - return new_stmt; + /* Assuming c = x CMP y. */ + bool op1_minus_onep = integer_minus_onep (op1); + bool op2_zerop = integer_zerop (op2); + tree vtype = TREE_TYPE (lhs); + machine_mode vmode = TYPE_MODE (vtype); + /* Try to fold r = c ? -1 : 0 to r = c. */ + if (op1_minus_onep && op2_zerop) + { + tree conv_op = build1 (VIEW_CONVERT_EXPR, vtype, op0); + return gimple_build_assign (lhs, conv_op); + } + /* Try to fold r = c ? -1 : z to r = c | z, or + r = c ? c : z. */ + if (op1_minus_onep) + { + tree conv_op = build1 (VIEW_CONVERT_EXPR, vtype, op0); + tree new_op0 = make_ssa_name (vtype); + gassign *new_stmt = gimple_build_assign (new_op0, conv_op); + gsi_insert_seq_before (gsi, new_stmt, GSI_SAME_STMT); + if (optab_handler (ior_optab, vmode) != CODE_FOR_nothing) + /* r = c | z */ + return gimple_build_assign (lhs, BIT_IOR_EXPR, new_op0, + op2); + /* r = c ? c : z */ + op1 = new_op0; + } + /* Try to fold r = c ? z : 0 to r = c & z, or + r = c ? z : c. */ + else if (op2_zerop) + { + tree conv_op = build1 (VIEW_CONVERT_EXPR, vtype, op0); + tree new_op0 = make_ssa_name (vtype); + gassign *new_stmt = gimple_build_assign (new_op0, conv_op); + gsi_insert_seq_before (gsi, new_stmt, GSI_SAME_STMT); + if (optab_handler (and_optab, vmode) != CODE_FOR_nothing) + /* r = c | z */ + return gimple_build_assign (lhs, BIT_AND_EXPR, new_op0, + op1); + /* r = c ? z : c */ + op2 = new_op0; + } } /* When the compare has EH we do not want to forward it when