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 3CDBE3858D33 for ; Mon, 4 Sep 2023 01:25:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3CDBE3858D33 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 383LmlIK022522 for ; Sun, 3 Sep 2023 18:25:56 -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=kp4q0aYVl2iQxHfLtiYFMhDy1ZHTgpendjArvWI7ExE=; b=T5HuyTJBnoG8r3MfCn+njDADlMKT/HDntjFg0lux/EiVK9KypC4G76xA0SkBAWJJSgMM 7bg1wrmFUfeyeclRDREp3Mv0N+BT3KFu0ONa8aNoD/rTHopxvuziMWVKV5u+9S+WfBXC raXjscLwSeAyf15IsRlwi6SQ+ngBYCukrTW9yPEkr8U8GiyLDO91qcsyZDv1LYu52Zhk Sehn1q/CQnPwxA76nO36qnCWkhRw2Si8yFGCRtM9ah9ZmhT+TmfutlUACkMxh4zNuM7P Bcfi4f4gZx7ivKEpuHql1/cCK14q45vfviGMOW2m4bi6zhUZWrrkqg8K2kzRr3m8uxw2 Rg== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3sv4jk3tn6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sun, 03 Sep 2023 18:25:56 -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 18:25:54 -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 18:25:54 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 68E983F704E; Sun, 3 Sep 2023 18:25:54 -0700 (PDT) From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH] MATCH: Add `(x | c) & ~(y | c)` and `x & ~(y | x)` patterns [PR98710] Date: Sun, 3 Sep 2023 18:25:36 -0700 Message-ID: <20230904012536.930677-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: zTK6i647hrnXMYfVPLObRVX7HpH3fAr2 X-Proofpoint-ORIG-GUID: zTK6i647hrnXMYfVPLObRVX7HpH3fAr2 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_21,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,KAM_SHORT,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: Adding some more simple bit_and/bit_ior patterns. How often these show up, I have no idea. This was tested on top of https://gcc.gnu.org/pipermail/gcc-patches/2023-September/629174.html . OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: PR tree-optimization/98710 * match.pd (`(x | c) & ~(y | c)`, `(x & c) | ~(y & c)`): New pattern. (`x & ~(y | x)`, `x | ~(y & x)`): New patterns. gcc/testsuite/ChangeLog: PR tree-optimization/98710 * gcc.dg/tree-ssa/andor-7.c: New test. * gcc.dg/tree-ssa/andor-8.c: New test. --- gcc/match.pd | 14 +++++++++++++- gcc/testsuite/gcc.dg/tree-ssa/andor-7.c | 16 ++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/andor-8.c | 19 +++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/andor-7.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/andor-8.c diff --git a/gcc/match.pd b/gcc/match.pd index 3495f9451d1..a3f507a1e2e 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1995,7 +1995,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* (x & y) | (x | z) -> (x | z) */ (simplify (bitop:c (rbitop:c @0 @1) (bitop:c@3 @0 @2)) - @3)) + @3) + /* (x | c) & ~(y | c) -> x & ~(y | c) */ + /* (x & c) | ~(y & c) -> x | ~(y & c) */ + (simplify + (bitop:c (rbitop:c @0 @1) (bit_not@3 (rbitop:c @1 @2))) + (bitop @0 @3)) + /* x & ~(y | x) -> 0 */ + /* x | ~(y & x) -> -1 */ + (simplify + (bitop:c @0 (bit_not (rbitop:c @0 @1))) + (if (bitop == BIT_AND_EXPR) + { build_zero_cst (type); } + { build_minus_one_cst (type); }))) /* ((x | y) & z) | x -> (z & y) | x ((x ^ y) & z) | x -> (z & y) | x */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/andor-7.c b/gcc/testsuite/gcc.dg/tree-ssa/andor-7.c new file mode 100644 index 00000000000..63b70fa7888 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/andor-7.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-original" } */ +/* PR tree-optimization/98710 */ + +signed foo(signed x, signed y, signed z) +{ + return (x | z) & ~(y | z); // x & ~(y | z); +} +// Note . here is `(` or `)` +/* { dg-final { scan-tree-dump "return x \& ~.y \\| z.;|return ~.y \\| z. \& x;" "original" } } */ + +signed foo_or(signed a, signed b, signed c) +{ + return (a & c) | ~(b & c); // a | ~(b & c); +} +/* { dg-final { scan-tree-dump "return a \\| ~.b \& c.;|return ~.b \& c. \\| a;" "original" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/andor-8.c b/gcc/testsuite/gcc.dg/tree-ssa/andor-8.c new file mode 100644 index 00000000000..0c2eb4c1a00 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/andor-8.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-original" } */ +/* PR tree-optimization/98710 */ + +signed foo2(signed a, signed b, signed c) +{ + return (a & ~(b | a)) & c; // 0 +} +/* { dg-final { scan-tree-dump "return 0;" "original" } } */ +signed foo2_or(signed x, signed y, signed z) +{ + return (x | ~(y & x)) & z; // -1 & z -> z +} + +/* { dg-final { scan-tree-dump "return z;" "original" } } */ +/* All | and & should have been removed. */ +/* { dg-final { scan-tree-dump-not "~" "original" } } */ +/* { dg-final { scan-tree-dump-not " \& " "original" } } */ +/* { dg-final { scan-tree-dump-not " \\| " "original" } } */ -- 2.31.1