From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 8680D3858C1F for ; Fri, 28 Apr 2023 17:02:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8680D3858C1F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=marvell.com Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33SA5A6V003432 for ; Fri, 28 Apr 2023 10:02:24 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=vjyAA5bNtbw2ugpnRRHUeTCQ6qGJzTrVlmz30deXH6U=; b=keZNaiA9XrQH3DtkH1dPi0wAPCzQydf1BLVk8WgBa1rlQth+qgEfkRrWwcuUuGWk9YQ/ ij25FE3Btl3vwcTC79RNTqg2RzL4Bsx3U83Bn+5iPPlSAQtA0cT6J5y9fKFen9+wKIg1 Ysq5D8QX+U2VMjgSXHCpurIG2yeyVv/qA2gON7LHiZavOlUGV0xtPhW2DMyExkK/hosg ht0/uDrYtfazl/YgnR9dYXwLZJdv9AMdXOCnEXjRcuA2datREa7tDGYTFHGc4egnLNRs tjLG01+brYsfJzezChwSCVxl7EHMaPl46XukRgGJOYdSdwIj5wWPC2jklZZo4ScqxUqf Lw== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3q85x630a2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Fri, 28 Apr 2023 10:02:24 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 28 Apr 2023 10:02:22 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Fri, 28 Apr 2023 10:02:22 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 8007E5B6933; Fri, 28 Apr 2023 10:02:22 -0700 (PDT) From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 2/2] MATCH: add some of what phiopt's builtin_zero_pattern did Date: Fri, 28 Apr 2023 10:02:13 -0700 Message-ID: <20230428170213.677572-3-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230428170213.677572-1-apinski@marvell.com> References: <20230428170213.677572-1-apinski@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: CtASQ_mcs4gBixsIy2ykLZC9FLv-njkx X-Proofpoint-ORIG-GUID: CtASQ_mcs4gBixsIy2ykLZC9FLv-njkx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-28_04,2023-04-27_01,2023-02-09_01 X-Spam-Status: No, score=-14.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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: This adds the patterns for POPCOUNT BSWAP FFS PARITY CLZ and CTZ. For "a != 0 ? FUNC(a) : CST". CLRSB, CLRSBL, and CLRSBLL will be moved next. Note this is not enough to remove cond_removal_in_builtin_zero_pattern as we need to handle the case where there is an NOP_CONVERT inside the conditional to move out of the condition inside match_simplify_replacement. OK? Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * match.pd: Add patterns for "a != 0 ? FUNC(a) : CST" for FUNC of POPCOUNT BSWAP FFS PARITY CLZ and CTZ. --- gcc/match.pd | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index e17597ead26..0e782cde71d 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -52,6 +52,8 @@ along with GCC; see the file COPYING3. If not see gt ge eq ne le lt unordered ordered ungt unge unlt unle uneq ltgt) (define_operator_list simple_comparison lt le eq ne ge gt) (define_operator_list swapped_simple_comparison gt ge eq ne le lt) +(define_operator_list BSWAP BUILT_IN_BSWAP16 BUILT_IN_BSWAP32 + BUILT_IN_BSWAP64 BUILT_IN_BSWAP128) #include "cfn-operators.pd" @@ -4313,8 +4315,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (complex (convert:itype @0) (negate (convert:itype @1))))) /* BSWAP simplifications, transforms checked by gcc.dg/builtin-bswap-8.c. */ -(for bswap (BUILT_IN_BSWAP16 BUILT_IN_BSWAP32 - BUILT_IN_BSWAP64 BUILT_IN_BSWAP128) +(for bswap (BSWAP) (simplify (bswap (bswap @0)) @0) @@ -7780,6 +7781,42 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (bit_xor (PARITY:s @0) (PARITY:s @1)) (PARITY (bit_xor @0 @1))) +/* a != 0 ? FUN(a) : 0 -> Fun(a) for some builtin functions. */ +(for func (POPCOUNT BSWAP FFS PARITY) + (simplify + (cond (ne @0 integer_zerop@1) (func@4 (convert? @2)) integer_zerop@3) + @4)) + +#if GIMPLE +/* a != 0 ? CLZ(a) : CST -> .CLZ(a) where CST is the result of the internal function for 0. */ +(for func (CLZ) + (simplify + (cond (ne @0 integer_zerop@1) (func (convert?@4 @2)) INTEGER_CST@3) + (with { int val; + internal_fn ifn = IFN_LAST; + if (direct_internal_fn_supported_p (IFN_CLZ, type, OPTIMIZE_FOR_BOTH) + && CLZ_DEFINED_VALUE_AT_ZERO (SCALAR_INT_TYPE_MODE (type), + val) == 2) + ifn = IFN_CLZ; + } + (if (ifn == IFN_CLZ && wi::to_widest (@3) == val) + (IFN_CLZ @4))))) + +/* a != 0 ? CTZ(a) : CST -> .CTZ(a) where CST is the result of the internal function for 0. */ +(for func (CTZ) + (simplify + (cond (ne @0 integer_zerop@1) (func (convert?@4 @2)) INTEGER_CST@3) + (with { int val; + internal_fn ifn = IFN_LAST; + if (direct_internal_fn_supported_p (IFN_CTZ, type, OPTIMIZE_FOR_BOTH) + && CTZ_DEFINED_VALUE_AT_ZERO (SCALAR_INT_TYPE_MODE (type), + val) == 2) + ifn = IFN_CTZ; + } + (if (ifn == IFN_CTZ && wi::to_widest (@3) == val) + (IFN_CTZ @4))))) +#endif + /* Common POPCOUNT/PARITY simplifications. */ /* popcount(X&C1) is (X>>C2)&1 when C1 == 1<