Message ID | 20230824191455.3547513-2-apinski@marvell.com |
---|---|
State | Unresolved |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> 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 <ouuuleilei@gmail.com> (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 <ouuuleilei@gmail.com>; 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 <gcc-patches@gcc.gnu.org>; 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 <gcc-patches@gcc.gnu.org>; 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 <gcc-patches@gcc.gnu.org>; 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: <gcc-patches@gcc.gnu.org> CC: Andrew Pinski <apinski@marvell.com> 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Andrew Pinski via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Andrew Pinski <apinski@marvell.com> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1775139150677850637 X-GMAIL-MSGID: 1775139150677850637 |
Series |
[1/3] MATCH: Move `a ? one_zero : one_zero` matching after min/max matching
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | warning | Git am fail log |
Commit Message
Andrew Pinski
Aug. 24, 2023, 7:14 p.m. UTC
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(+)
Comments
On Thu, Aug 24, 2023 at 9:16 PM Andrew Pinski via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > 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. Also works for xor, no? > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. OK with or without adding XOR. Richard. > 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. */ > -- > 2.31.1 >
On Thu, Aug 24, 2023 at 11:37 PM Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > On Thu, Aug 24, 2023 at 9:16 PM Andrew Pinski via Gcc-patches > <gcc-patches@gcc.gnu.org> wrote: > > > > 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. > > Also works for xor, no? No, because IOR is a saturation operation while XOR is not. So if you know that x and C are full subsets (nonzero(x) & ~nonzero(C) == 0) then A^C is not the constant C but rather just (~A)&C which we already a pattern for that to turn it back in to A^C: /* Simplify (~X & Y) to X ^ Y if we know that (X & ~Y) is 0. */ The only thing you can do for XOR is that if you have `A ^ B` and A and B are known not to share any bits in common (that is nonzero(A) & nonzero(B) == 0), you can convert it to `A | B` (that is what simplify-rtx.cc does). Which looks like we don't do on the gimple level. > > > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. > > OK with or without adding XOR. Ok. Thanks, Andrew > > Richard. > > > 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. */ > > -- > > 2.31.1 > >
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. */