From patchwork Thu Aug 24 19:14:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 136865 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a7d1:0:b0:3f2:4152:657d with SMTP id p17csp1335860vqm; Thu, 24 Aug 2023 12:16:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF2NCFpx9Sp1Uxsh6S8tVsfkKzlXMfAcaOERMisO1EYbw4ZVn6rDWaCBojn49ki7DCwp/+y X-Received: by 2002:aa7:c38e:0:b0:523:3e5d:8aa2 with SMTP id k14-20020aa7c38e000000b005233e5d8aa2mr13494077edq.14.1692904616458; Thu, 24 Aug 2023 12:16:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692904616; cv=none; d=google.com; s=arc-20160816; b=y8dzL7V1iiH8QlcQ6Pm/V9sGgttqn3LPnqh4e0wpD+ERroKO/+q77wMTYi6yc9a7R1 tHPJ/7uW9/h+foMds3COHlZ+1MhjU8jOvbKOg+ID1UnIaAEtK1QS0fY6ztKG2dsqwNP+ WPYq4tvx4s4CMBPDQL3DQimEN4VTnj3E5IsEnKkVyWoxr4l0cI/HCHjs99NYwVzyMrdX H+66nxVq4+x9vRHT53Kqah9Pst7rwV7gkv8XaC7U+rENPQTNO9f7V/wdHOMj0HEBLIvP /praCj+krUBV/J23IxcZPM/ZQKuonp27/P7vf2j7jyr8DPNg77oVp6870vmYlsRIoft5 Fkxw== 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=OMrbTz3XG11+rfXwTbDpkVkihwGZ1jOJi1xNHElmE38=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=zv7y2I7gvGkuqGPolA99ZAuK40EKjTqlf/drYbNULTtLL8u/3SPYb9eC+KHXjC/fqq QL5BS0zij27s+Jc4iy52YeG/UxB8qmXI4QIgdlGJrBpse6XY2p44cT7tb86VJ/u1Et1O PZioZq04ti+qmoVmuwGBlFgYGlQEE5T7GMJ1FmcK/hkBSdVSQ2mb+bpF4XZGIPHH2Q+u +piJf8S+ABC67+i0/vPAG/6olp8fxTY54Xabotc7MsUJFtldplii1sZdVSQSTbACsSao FEvUsqWN4goFlQQROJV20F0xt+wpnlYqUoSmlRzUkamZL0OxExoW0TRAMXNcGhAbtxo4 4grg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="NMn/buT9"; 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 r3-20020aa7d143000000b005255ad4798bsi114442edo.455.2023.08.24.12.16.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 12:16:56 -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="NMn/buT9"; 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 7728D3851C20 for ; Thu, 24 Aug 2023 19:15:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7728D3851C20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692904557; bh=OMrbTz3XG11+rfXwTbDpkVkihwGZ1jOJi1xNHElmE38=; 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=NMn/buT9fCbUsHb7uxrqwUxalV4v9Yh1Y9C3qbBb9XlzBnHsNOLd3lDZY8DO26KPR j7nWIM/fCiSlrutgII6cjZLphJzAsJKzWDmmoNS1u4uxdUxETd5qRSJY96VwtW2hbj Y733evMi3+8UNj8OOz5an+umO1zwMf7VCYb8Fj3g= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id 288E7385800A for ; Thu, 24 Aug 2023 19:15:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 288E7385800A Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37OFgOAB012153 for ; Thu, 24 Aug 2023 12:15:07 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3sn20d14u9-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 24 Aug 2023 12:15:07 -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; Thu, 24 Aug 2023 12:15:04 -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; Thu, 24 Aug 2023 12:15:04 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id E012A3F7087; Thu, 24 Aug 2023 12:15:03 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 2/3] MATCH: `a | C -> C` when we know that `a & ~C == 0` Date: Thu, 24 Aug 2023 12:14:54 -0700 Message-ID: <20230824191455.3547513-2-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230824191455.3547513-1-apinski@marvell.com> References: <20230824191455.3547513-1-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: HHHWhcr9chOTS9Q1neSt3zxuH8p1De5O X-Proofpoint-ORIG-GUID: HHHWhcr9chOTS9Q1neSt3zxuH8p1De5O 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-08-24_15,2023-08-24_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.29 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: 1775139150677850637 X-GMAIL-MSGID: 1775139150677850637 Even though this is handled by other code inside both VRP and CCP, sometimes we want to optimize this outside of VRP and CCP. An example is given in PR 106677 where phiopt will happen after VRP (which removes a cast for a comparison) and then phiopt will optimize the phi to be `a | 1` which can then be optimized to `1` due to this patch. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. Note Similar code already exists in simplify_rtx for the RTL level; it was moved from combine to simplify_rtx in r0-72539-gbd1ef757767f6d. gcc/ChangeLog: * match.pd (`a | C -> C`): New pattern. --- gcc/match.pd | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gcc/match.pd b/gcc/match.pd index c87a0795667..3bbeceb37b4 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1456,6 +1456,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && wi::bit_and_not (get_nonzero_bits (@0), wi::to_wide (@1)) == 0) @0)) +/* x | C -> C if we know that x & ~C == 0. */ +(simplify + (bit_ior SSA_NAME@0 INTEGER_CST@1) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && wi::bit_and_not (get_nonzero_bits (@0), wi::to_wide (@1)) == 0) + @1)) #endif /* ~(~X - Y) -> X + Y and ~(~X + Y) -> X - Y. */