From patchwork Sat Sep 2 15:09:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 137426 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp203186vqo; Sat, 2 Sep 2023 08:11:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE6EaujycaJ0qwbkU1OHEVDoXJ/PtDZdtITjF7dXs8pS8jiIVYzVd69W6ZueB+gySCaGrfg X-Received: by 2002:a17:907:2e02:b0:9a1:ea01:35b1 with SMTP id ig2-20020a1709072e0200b009a1ea0135b1mr3953391ejc.62.1693667490884; Sat, 02 Sep 2023 08:11:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693667490; cv=none; d=google.com; s=arc-20160816; b=TqYwjw9C4/tX1lmpoKK1XEQ7SK7wQIc6qXlOlNftzVsFl98sVUS39cViFgkoLQ43EE O+1OTrQM9IrJw3mVsxqA2nFeUsP0efViMiZMFDMLeUU3e9sBlt4fvX24+YAFGoqo7NEK LygH+pDPh9tt9yALyNTGDTLmXXcKV/nDJ7/jEmRmTHjTimeLH4zqy1iKOyN0vZM0BByy 6mu48jCx5+HFUGHwkyJ1v5i9tz7jWw2R722trqKkScsQeJWcujxe+2DEdMjfnUMhB7HR 2CwuV1VqV0Ci4j3Yt0y/Ac23P14Rcuze8WPopB278pB4o3iSRCLX4UmN4QCMxRSNHIWO oGqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=l+UgYnQ+d3QFkH4PjLBCyNCoIW0j08qnbO5Njip16/A=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=RgkQP0FsKkr6vcPmw8zbFAsrCjCHtz7LGW4iMfERFmEqlEkcxyDeunXLDbk3WXSnl9 /4QmvsWKzSAdPrJhMf/QYztwO2v2NO51igq16Cz+n756Qr19ykKcYYwyGDKLh9J1WZ3T JfBfNVnuRHmMXEe9f9QrqN4hTw+LQ3yT+m7gjJNxKwfRvG8DHyL4PuIidZZOmeyxIhcq upn9WNCU3ZMhhV8GmaqZ9muJdyJ1zs/cy5UIgbnpcgZINTBrCR05BZHzmlq3l2FvctyI hIm9rHBT0EixWZF5+4anbq2wFJncf7Rbb/01GsfUF6B1Ch8wgPPFVsfJfZoY7oxzKEu8 5deA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QLBZfqDc; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 ti1-20020a170907c20100b00973a7283de2si3575746ejc.505.2023.09.02.08.11.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Sep 2023 08:11:30 -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; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QLBZfqDc; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5E53C385DC0F for ; Sat, 2 Sep 2023 15:10:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5E53C385DC0F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693667455; bh=l+UgYnQ+d3QFkH4PjLBCyNCoIW0j08qnbO5Njip16/A=; h=To:CC:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=QLBZfqDcjz3GZXjcqQQzEOU8Lj1Ve/kCUCi1GA55bZuX64FInap/6r+4I9PIlHNWd seYvpbZL8dXLNCv5C+0mOIJnTs8TRsM3SAK/PRrv3fw8mHfTv1HlsOrjeaWKygoRrj Lk3eVVCwpPTX4gohMTClkEPi+K1yhn6JWksQA2ws= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id C30FE3858CDB for ; Sat, 2 Sep 2023 15:10:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C30FE3858CDB 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 382ErQR0011467 for ; Sat, 2 Sep 2023 08:10:08 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3sv2dp0hsk-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 02 Sep 2023 08:10:07 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sat, 2 Sep 2023 08:10:06 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Sat, 2 Sep 2023 08:10:06 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 3F73A3F7083; Sat, 2 Sep 2023 08:10:06 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 3/3] MATCH: Replace all uses of ssa_name_has_boolean_range with zero_one_valued_p Date: Sat, 2 Sep 2023 08:09:57 -0700 Message-ID: <20230902150957.845269-3-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230902150957.845269-1-apinski@marvell.com> References: <20230902150957.845269-1-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: rUR-U4wnCsDGEhaPAs7swO005gkr-JiG X-Proofpoint-GUID: rUR-U4wnCsDGEhaPAs7swO005gkr-JiG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-02_10,2023-08-31_01,2023-05-22_02 X-Spam-Status: No, score=-14.6 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_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: , X-Patchwork-Original-From: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1775939083291367915 X-GMAIL-MSGID: 1775939083291367915 This replaces all uses of ssa_name_has_boolean_range with zero_one_valued_p except for the one in the definition of zero_one_valued_p. This simplifies the code in general and makes only one way of saying we have a range of [0,1]. Note this depends on the patch that adds ssa_name_has_boolean_range usage to zero_one_valued_p. OK? Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * match.pd: Move zero_one_valued_p and truth_valued_p towards the begnining of the file. (X / bool_range_Y): Use zero_one_valued_p instead of ssa_name_has_boolean_range. Move after all other `X / Y` patterns. Add check to make sure bool_range_Y is not the literal 0. (1 - a): Use zero_one_valued_p instead of ssa_name_has_boolean_range (-(type)!A): Likewise. --- gcc/match.pd | 96 ++++++++++++++++++++++++---------------------------- 1 file changed, 45 insertions(+), 51 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index 04033546fc1..5270e4104ac 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -172,6 +172,38 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) ) #endif +/* Try simple folding for X op !X, and X op X with the help + of the truth_valued_p and logical_inverted_value predicates. */ +(match truth_valued_p + @0 + (if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) == 1))) +(for op (tcc_comparison truth_and truth_andif truth_or truth_orif truth_xor) + (match truth_valued_p + (op @0 @1))) +(match truth_valued_p + (truth_not @0)) + +/* zero_one_valued_p will match when a value is known to be either + 0 or 1 including constants 0 or 1. + Signed 1-bits includes -1 so they cannot match here. */ +/* Note ssa_name_has_boolean_range uses + the current ranger while tree_nonzero_bits uses only + the global one. */ +(match zero_one_valued_p + SSA_NAME@0 + (if (ssa_name_has_boolean_range (@0)))) +(match zero_one_valued_p + @0 + (if (INTEGRAL_TYPE_P (type) + && (TYPE_UNSIGNED (type) + || TYPE_PRECISION (type) > 1) + && wi::leu_p (tree_nonzero_bits (@0), 1)))) +(match zero_one_valued_p + truth_valued_p@0 + (if (INTEGRAL_TYPE_P (type) + && (TYPE_UNSIGNED (type) + || TYPE_PRECISION (type) > 1)))) + /* Transform likes of (char) ABS_EXPR <(int) x> into (char) ABSU_EXPR ABSU_EXPR returns unsigned absolute value of the operand and the operand of the ABSU_EXPR will have the corresponding signed type. */ @@ -493,13 +525,6 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (div @0 integer_minus_onep@1) (if (!TYPE_UNSIGNED (type)) (negate @0))) - /* X / bool_range_Y is X. */ - (simplify - (div @0 SSA_NAME@1) - (if (INTEGRAL_TYPE_P (type) - && ssa_name_has_boolean_range (@1) - && !flag_non_call_exceptions) - @0)) /* X / X is one. */ (simplify (div @0 @0) @@ -525,7 +550,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && TYPE_OVERFLOW_UNDEFINED (type) && !integer_zerop (@0) && (!flag_non_call_exceptions || tree_expr_nonzero_p (@0))) - { build_minus_one_cst (type); }))) + { build_minus_one_cst (type); })) + /* X / bool_range_Y is X. */ + (simplify + (div @0 zero_one_valued_p@1) + (if (INTEGRAL_TYPE_P (type) + /* But not for X / 0 so that we can get the proper warnings and errors. */ + && !integer_zerop (@1) + && !flag_non_call_exceptions) + @0))) /* For unsigned integral types, FLOOR_DIV_EXPR is the same as TRUNC_DIV_EXPR. Rewrite into the latter in this case. Similarly @@ -1865,14 +1898,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (plus @0 (negate @1)))) /* 1 - a is a ^ 1 if a had a bool range. */ -/* This is only enabled for gimple as sometimes - cfun is not set for the function which contains - the SSA_NAME (e.g. while IPA passes are happening, - fold might be called). */ (simplify - (minus integer_onep@0 SSA_NAME@1) - (if (INTEGRAL_TYPE_P (type) - && ssa_name_has_boolean_range (@1)) + (minus integer_onep@0 zero_one_valued_p@1) + (if (INTEGRAL_TYPE_P (type)) (bit_xor @1 @0))) /* Other simplifications of negation (c.f. fold_negate_expr_1). */ @@ -2018,17 +2046,6 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (cst2) (bitop @0 { cst2; })))))))) -/* Try simple folding for X op !X, and X op X with the help - of the truth_valued_p and logical_inverted_value predicates. */ -(match truth_valued_p - @0 - (if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) == 1))) -(for op (tcc_comparison truth_and truth_andif truth_or truth_orif truth_xor) - (match truth_valued_p - (op @0 @1))) -(match truth_valued_p - (truth_not @0)) - (match (logical_inverted_value @0) (truth_not @0)) (match (logical_inverted_value @0) @@ -2060,27 +2077,6 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (bit_not (bit_not @0)) @0) -/* zero_one_valued_p will match when a value is known to be either - 0 or 1 including constants 0 or 1. - Signed 1-bits includes -1 so they cannot match here. */ -/* Note ssa_name_has_boolean_range uses - the current ranger while tree_nonzero_bits uses only - the global one. */ -(match zero_one_valued_p - SSA_NAME@0 - (if (ssa_name_has_boolean_range (@0)))) -(match zero_one_valued_p - @0 - (if (INTEGRAL_TYPE_P (type) - && (TYPE_UNSIGNED (type) - || TYPE_PRECISION (type) > 1) - && wi::leu_p (tree_nonzero_bits (@0), 1)))) -(match zero_one_valued_p - truth_valued_p@0 - (if (INTEGRAL_TYPE_P (type) - && (TYPE_UNSIGNED (type) - || TYPE_PRECISION (type) > 1)))) - /* Transform { 0 or 1 } * { 0 or 1 } into { 0 or 1 } & { 0 or 1 }. */ (simplify (mult zero_one_valued_p@0 zero_one_valued_p@1) @@ -5486,12 +5482,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* -(type)!A -> (type)A - 1. */ (simplify - (negate (convert?:s (logical_inverted_value:s @0))) + (negate (convert?:s (logical_inverted_value:s zero_one_valued_p@0))) (if (INTEGRAL_TYPE_P (type) && TREE_CODE (type) != BOOLEAN_TYPE - && TYPE_PRECISION (type) > 1 - && TREE_CODE (@0) == SSA_NAME - && ssa_name_has_boolean_range (@0)) + && TYPE_PRECISION (type) > 1) (plus (convert:type @0) { build_all_ones_cst (type); }))) /* A + (B vcmp C ? 1 : 0) -> A - (B vcmp C ? -1 : 0), since vector comparisons