From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=marvell.com 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=HsODIb+nd04CKiXxnKeyl63+wwmhiBz2nWhGRGHbhz0=; b=Zhd8sIJsQqbXHWyrAIBTO6qmzAw2E3l4lAkAkHEkrzoc06bFkBkY+Ka4VJjRFs455n/M d39j277opLak8rez8Xy4XxsqHxz6T07Ae4j9lf58lVF90sDVBPaUCQb/hT7ryweF454b Z3Ldr8lVnUI8cegZ/i/EeRPjGEUQtZKcWEDdn6SddjsXOjcWuGKw7P6WEM6qJJTOWiLB eIPPLdhX9K7XmZltV3rBuhsFPS5C0KvbddErIXNK5TjR3iUCHns3nV/0tJdqPpc7bZJw xyzni1foUWGYUEuQIYV9vQZV+EDAuKJSFqekcL3jzX5KLe+gI7iogu25pcS2M+Uf6E+s Rw== 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) From: Andrew Pinski 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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 List-Id: 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" } } */ -- 2.31.1