From patchwork Sun Sep 3 20:49:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 137433 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp754443vqo; Sun, 3 Sep 2023 13:50:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEEzVKmML/1b4TodkrtlRbT4bX6I+onKNQrJUbAm8IDvORxmhoOh3C+TkkZGLIv5vUcg+Nt X-Received: by 2002:aa7:d8d7:0:b0:52a:6497:d02b with SMTP id k23-20020aa7d8d7000000b0052a6497d02bmr6542936eds.16.1693774244009; Sun, 03 Sep 2023 13:50:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693774243; cv=none; d=google.com; s=arc-20160816; b=LhCVvL2PoCQNSw+gw/jEii6AGzGW+3TejeB6F/hF+RqUZluQFQ8pT5jBzvD+vGVI8K kBEDH7FeI1w4f1Hlwxsw0hWLeTNZYp81YclX1CSZMwW9PhxhLUtRhiLnd+SfzJosevb9 NCRTZqB0w45vqybPpTMDiLKydM29ucBMLOwzMHHfRpSgv1PP2wQjkgccMnlsBZFJ9dUZ e/uyXDsu9ZcDpYpGj89cnv9ebLBDOTaL/KjCTbAcGTdSfIU9sBLKEFmb2QhXkDwUDoyG pDi7aZiZL841szySX2hIOxOCY5iX1Ik1fKXGxjlyzMBuUeufQYj9CEjmd2apik5NIzbh 6P7Q== 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=HsODIb+nd04CKiXxnKeyl63+wwmhiBz2nWhGRGHbhz0=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=DF8VsprxzDs6C7tqhWPQPr4aMVZr/1uG5MlchsZrByRDRTTX2wM9T7LoNZuHSW+mwv ntXlVq4/bk9HyF6lPJRa+q8ZLk9RRc20nJFv7n7Au5MG6iROsspZKg18PE5bP5hfNDDC T9lDuMOLWMDHU9P7/2xKn1byEGu4ZL1mIxaVVc1hoTEtKSw0VK7Ba9XXzAjJ0b/BuR5H 87SMNaiB1DPDp65SB8RN+tFurQJMvLodBTVMpW9XfPR1MsxaiggXYV1PeaGMe20TmHSt 9zaImEvsMZJuktbqifpKnyY5hTjItKLat6UkiZZK7BZutpCHXkrPPzlIRtuPCS9m8xRj IVFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ZU+oLIn2; 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 k7-20020a05640212c700b0051a5a6676dfsi5330223edx.23.2023.09.03.13.50.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Sep 2023 13:50:43 -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=ZU+oLIn2; 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 74BA03858004 for ; Sun, 3 Sep 2023 20:50:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 74BA03858004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693774242; bh=HsODIb+nd04CKiXxnKeyl63+wwmhiBz2nWhGRGHbhz0=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=ZU+oLIn2kl7oJnM3OwinEa319j8uYC7DlHjJYDkTWC9HVwCEehBdHHM9rM8I3gMep urFZW3ZC62FDERyTd0XxBev70Orkt/z8uj3i6SzQDC97cB/VOc0E5XRHFtqyFDB3fr clQ+vcWOWBQI7l5/x06GCE1chhjkOiP8q21j16ec= 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 D6A323858D33 for ; Sun, 3 Sep 2023 20:49:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D6A323858D33 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 383K02bA014622 for ; Sun, 3 Sep 2023 13:49:58 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3sv4jk3a2k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sun, 03 Sep 2023 13:49:57 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sun, 3 Sep 2023 13:49:56 -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; Sun, 3 Sep 2023 13:49:56 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id A47643F7074; Sun, 3 Sep 2023 13:49:55 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] MATCH: Add pattern for `(x | y) & (x & z)` Date: Sun, 3 Sep 2023 13:49:47 -0700 Message-ID: <20230903204947.918766-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: JCWU1Mbto__fCW4sMXLb3TegRfPMEFGc X-Proofpoint-ORIG-GUID: JCWU1Mbto__fCW4sMXLb3TegRfPMEFGc 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-03_18,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: 1776051021956664095 X-GMAIL-MSGID: 1776051021956664095 Like the pattern already there for `(x | y) & x`, this adds a simple pattern to optimize `(x | y) & (x & z)` to just `x & z`. OK? Bootstrapped and tested on x86-64-linux-gnu with no regressions. gcc/ChangeLog: PR tree-optimization/103536 * match.pd (`(x | y) & (x & z)`, `(x & y) | (x | z)`): New patterns. gcc/testsuite/ChangeLog: PR tree-optimization/103536 * gcc.dg/tree-ssa/andor-6.c: New test. * gcc.dg/tree-ssa/andor-bool-1.c: New test. --- gcc/match.pd | 7 ++++++- gcc/testsuite/gcc.dg/tree-ssa/andor-6.c | 19 +++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/andor-bool-1.c | 13 +++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/andor-6.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/andor-bool-1.c diff --git a/gcc/match.pd b/gcc/match.pd index 3efc971f7f6..3495f9451d1 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1990,7 +1990,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (with { bool wascmp; } (if (bitwise_inverted_equal_p (@0, @2, wascmp) && (!wascmp || element_precision (type) == 1)) - (bitop @0 @1))))) + (bitop @0 @1)))) + /* (x | y) & (x & z) -> (x & z) */ + /* (x & y) | (x | z) -> (x | z) */ + (simplify + (bitop:c (rbitop:c @0 @1) (bitop:c@3 @0 @2)) + @3)) /* ((x | y) & z) | x -> (z & y) | x ((x ^ y) & z) | x -> (z & y) | x */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/andor-6.c b/gcc/testsuite/gcc.dg/tree-ssa/andor-6.c new file mode 100644 index 00000000000..32e11730f98 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/andor-6.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-original" } */ +/* PR tree-optimization/103536 */ + +int +orand(int a, int b, int c) +{ + return (a | b) & (a & c); // a & c +} + +/* { dg-final { scan-tree-dump "return a \& c;" "original" } } */ + +int +andor(int d, int e, int f) +{ + return (d & e) | (d | f); // d | f +} + +/* { dg-final { scan-tree-dump "return d \\| f;" "original" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/andor-bool-1.c b/gcc/testsuite/gcc.dg/tree-ssa/andor-bool-1.c new file mode 100644 index 00000000000..a1b974f3859 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/andor-bool-1.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* PR tree-optimization/103536 */ + +_Bool +src_1 (_Bool a, _Bool b) +{ + return (a || b) && (a && b); +} + +/* { dg-final { scan-tree-dump "a_\[0-9\]+.D. \& b_\[0-9\]+.D." "optimized" } } */ +/* { dg-final { scan-tree-dump-not "a_\[0-9\]+.D. \\\| b_\[0-9\]+.D." "optimized" } } */ +/* { dg-final { scan-tree-dump-not "if " "optimized" } } */