From patchwork Sat Sep 2 15:09:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 137425 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp203173vqo; Sat, 2 Sep 2023 08:11:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGNsFQMmRliBIDslVeMT+Jff+ni9Lp21ZSxjgP8NN7/pmfUWMCDnBY1wPHxZqSQofBhT6cP X-Received: by 2002:a05:6512:b08:b0:4fe:279b:7603 with SMTP id w8-20020a0565120b0800b004fe279b7603mr4490515lfu.14.1693667488936; Sat, 02 Sep 2023 08:11:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693667488; cv=none; d=google.com; s=arc-20160816; b=ad6wLbfQLfpDp7i6gxgIwN51c+4Uk3plLE0O2Ns6w5xQYcdbzwzhmDAZ9dKSisVvWr 6OKWjXsKISzBnTZXj9sR1ipZVmxdfexJ+HuE4uzu1b2lZIVmWlNkV07RecvyBeKYyee1 XII6mB+PoZI4E0ZMMl3R74iDhrLGTL7qIXgoqbPiqKu5JV7qjsehxTobTid6BBj9jW4B vXGuwioOWtjXiglf5Q8TytOGxJQ5DzE2A0AAf7IiEOcD4c8pH5qRZlwL1mSegtE3PZ4d ArXFhZ+31eD4kWXkKUB3yu6BOlBFTImpudbIrkUIFVw5cVIsrAHPN+7mSYdhU6r3s1TI cKoA== 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:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Qgci8hqJDp3fC7N1fgOgkHOOjdtY4Wvrg05dItgjvEk=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=l4QJgHfKwXqpT6plFe0LULblcRyZMV/CncJgWEhGQLaN5PUwbxa23yzMZgUqRqDnDU KDS8qKSRbwrDO+e9WiqNFGV925u8LItRcDXy6UNcmC1NrVlSICehTNLxZ+AWb3xi4iHl sgYZXCiz3SPJXglv7uvehEchpGojYrvzj4Dkp30ycAp6IlunkhBe1EQc3XvmrFqFTCEV r13MMtjgDQNjPbTAmp78z0RnHTvHvnHQT7bJXogNwmBRFtZ3nhJ0+zTV/2xDl2Q4uJZE xUG5QCMxcDz6scj+8JAWSuHk3hvLuZqqZ5Xs4H48fUpXBjQITD3muzKRVLsdugrwyNkf +mpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gtQa2RwC; 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 bf22-20020a0564021a5600b005254cb06c21si3820935edb.222.2023.09.02.08.11.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Sep 2023 08:11:28 -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=gtQa2RwC; 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 67D163856DD0 for ; Sat, 2 Sep 2023 15:10:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 67D163856DD0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693667454; bh=Qgci8hqJDp3fC7N1fgOgkHOOjdtY4Wvrg05dItgjvEk=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=gtQa2RwC1AkGkdheEhqt+wxFz9Br75ruwaoOPcTFgDALsAb7BjruGIL2DDD6TjpAC g1+lL379+a4bTLZPUMqq9Uayqy8YOWgU+m7qSFiFo7jKxO8PhCJqrizR3sEd0sCZwm PZDdnUnlhfcMrp4RYaDWFBKfci8JzicdnVRujlxY= 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 622D73858CD1 for ; Sat, 2 Sep 2023 15:10:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 622D73858CD1 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 382ErQQw011467 for ; Sat, 2 Sep 2023 08:10:07 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3sv2dp0hsk-1 (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:05 -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:05 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 318DA3F7084; Sat, 2 Sep 2023 08:10:05 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 1/3] Improve ssa_name_has_boolean_range slightly Date: Sat, 2 Sep 2023 08:09:55 -0700 Message-ID: <20230902150957.845269-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: ZrLPPN4xoNtOpjIsOTi3-AGR8iX9rJLr X-Proofpoint-GUID: ZrLPPN4xoNtOpjIsOTi3-AGR8iX9rJLr 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: 1775939081024700394 X-GMAIL-MSGID: 1775939081024700394 Right now ssa_name_has_boolean_range compares the range to range_true_and_false but instead we would get the nonzero bits and compare that to 1 instead (<=u 1). The nonzerobits comparison can be done in similar fashion. Note I think get_nonzero_bits is redundant as the range queury will return a more accurate version or the same value. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * tree-ssanames.cc (ssa_name_has_boolean_range): Improve using range's get_nonzero_bits and use `<=u 1`. --- gcc/tree-ssanames.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc index 6c362995c1a..7940d9954d8 100644 --- a/gcc/tree-ssanames.cc +++ b/gcc/tree-ssanames.cc @@ -535,10 +535,11 @@ ssa_name_has_boolean_range (tree op) { int_range<2> r; if (get_range_query (cfun)->range_of_expr (r, op) - && r == range_true_and_false (TREE_TYPE (op))) + && !r.undefined_p () + && wi::leu_p (r.get_nonzero_bits (), 1)) return true; - if (wi::eq_p (get_nonzero_bits (op), 1)) + if (wi::leu_p (get_nonzero_bits (op), 1)) return true; } From patchwork Sat Sep 2 15:09:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 137424 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp203132vqo; Sat, 2 Sep 2023 08:11:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF0jzbMQuXFEPrsjbv7fOp50lFuP1QxQhQ2Ibrz4YrinVkHUgT5y9r8u5MNhxln4mBz6tlw X-Received: by 2002:a17:906:6a0d:b0:9a2:26fa:8752 with SMTP id qw13-20020a1709066a0d00b009a226fa8752mr9283811ejc.10.1693667485262; Sat, 02 Sep 2023 08:11:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693667485; cv=none; d=google.com; s=arc-20160816; b=DYbanFBePRK4BUeAw5R0k9NorIEjv71Mp0ASnqCx8RPsYiPAxrFNlhvn6N+nIN4Qks /9aGlzVTwq+I8v3dEP7PawCnWzpTJJ8l03VWVP8InBYwan7uih21bNYLQ6eYxVpvqZLb c6l3bYcVVs03jOx8q3+BUDUNV81jWja54mrZ/ch7wWHy19ZlIgFAFSKnruBPABwheFdy fJeqRb+FpAceFvuXFtgdTtdIYDtOL+IHF//SI503pLTt4ZDCXwZoJS2OcOXD4No0/0cP TTZOiEIUfjIs1cMrTbON3D/jOVdOd+iFZKwrHCH1A+EzklimGUq6FYI8rieYkAxatRfr fBSg== 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=KZu4YcadqQln5Pw2E4OO92P6PgOEZbpOdC6Sqr1JSkg=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=OCu6gF1dHR7nF1CWVrh6P5Sjm4LYCVH/xVMmAvbm0vkIwis0YzSXU37Miyr0M3c6z5 bO2ZetfxzAiATmfJzG5h/MNekZV5avp5euT0KSeyW4IhYxFb/n/YnKNU19HzAZkCJiL8 RN/bxTN0fNFsr5IadT/mvJfv15v24tlq5CtJARRJ054SjAAc4Ced9rQOyA9yn3OPVZv3 IeSImaNkfN7QMH9xKIg/3J2+LIMNkoQNoaxWwYtyoKeGpkh+2RI0BUqLtxjyMRe9HnnS LMOwrHlz+t9sdkkzC2rmrqJdrhXaE6+dpWuIzRTN5sdvOaTG+8nB53NCa++Ko9wKQiRm c4NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=HehQeaog; 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 tk28-20020a170907c29c00b0099d61f05e05si3683707ejc.1023.2023.09.02.08.11.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Sep 2023 08:11:25 -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=HehQeaog; 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 B7113385B512 for ; Sat, 2 Sep 2023 15:10:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B7113385B512 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693667452; bh=KZu4YcadqQln5Pw2E4OO92P6PgOEZbpOdC6Sqr1JSkg=; 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=HehQeaog20tBQdpo3scjJhH+MQ2ZlZSLwq9uBoHvDeGz3wgBe0+cdObkHpjcf4ym6 nk7o+jDQSc6ZwAjksrAt/so1mZDloyUIv2e50oSR0sBsHff6xxaqlb5EpQW6HmLgqt enzJFQxmPR8MUo/Z21FghOiG2A/ZDpe0A2oyYM44= 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 622FB3858CDA for ; Sat, 2 Sep 2023 15:10:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 622FB3858CDA 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 382ErQQx011467 for ; Sat, 2 Sep 2023 08:10:07 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3sv2dp0hsk-2 (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:05 -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 B5EC53F709F; Sat, 2 Sep 2023 08:10:05 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 2/3] MATCH: Improve zero_one_valued_p by using ssa_name_has_boolean_range Date: Sat, 2 Sep 2023 08:09:56 -0700 Message-ID: <20230902150957.845269-2-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: el1J9dtrtQudbV1sonHMWW8dvTCnVapX X-Proofpoint-GUID: el1J9dtrtQudbV1sonHMWW8dvTCnVapX 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: 1775939077043226173 X-GMAIL-MSGID: 1775939077043226173 Currently zero_one_valued_p uses tree_nonzero_bits which uses the global ranges of the SSA Names. We can improve this via using ssa_name_has_boolean_range which uses the local ranges which are used while handling folding during VRP and other passes. OK? Bootstrapped and tested on x86_64 with no regressions. gcc/ChangeLog: * match.pd (zero_one_valued_p): Match SSA_NAMES where ssa_name_has_boolean_range returns true. --- gcc/match.pd | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gcc/match.pd b/gcc/match.pd index b94d71d2376..04033546fc1 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2063,6 +2063,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* 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) 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