From patchwork Mon Sep 4 01:25:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 137436 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp837076vqo; Sun, 3 Sep 2023 18:26:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEu5bG+ojWXhq6xcL85Uwlbx+AKYOnnBRJZMPJmwlilTYSyAu5kTi0ZpXQMQbjtZmmJ+ByD X-Received: by 2002:a05:6402:1e88:b0:51e:5bd5:fe7e with SMTP id f8-20020a0564021e8800b0051e5bd5fe7emr12186337edf.17.1693790808272; Sun, 03 Sep 2023 18:26:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693790808; cv=none; d=google.com; s=arc-20160816; b=uPvZl0HnrgijuaVGt6E+YeFMic6Wsts7xHvFuugzj5vArlEF3xK1ID9oRsa9D4fihh 7luw46SWwwasJ1znMPCItMIpCyR2LCRR0RK+fa3z0pFguNorq0J32rL6Y8BavSWSRKEg WP1bZ24GlscXfjQerDntbVPGk4Xjm1PVMLgvoEXEeb2kPLP+3+x4G+fom+pYFpncO+ie 8rd4vjqAcgRG4K2+MbFn3ySfDcrmMF3f6/7mlhrBtTvea25cHslcX7Nf8FkMKjvt1VBV f6mP8GRN3GvNwH/TX1K7maWxsS+3y1dw59w4OZAoH6DiPLuVOyLDgvyRjB/cT6Ho2L1m vJ3w== 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=kp4q0aYVl2iQxHfLtiYFMhDy1ZHTgpendjArvWI7ExE=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=EvKtEHC4KVGzQ0F8vq3AidZHMI91mAT9cNJN/hVSLvVqHUPHoZM7OKD81sVvloDCIV DAznyH56l3cQy08dTeqC2bmP+zclb0ScOLuMHBUEP07SFflqSnw3nicaubbNcqs6lwTk 7eHAlSZ8l+J/HeOjQy3MIRTiPg61UAMee2kbu8oThC2fUkuO5JlVZePe/BgtRKdNqY4r wYECtTXkbvLUv+kvLSMGjOjalVcgcIk4LLTqwyeXlisKnpb0qiccgunyWQslAwAcsqNe 9Yz7AwMMSXdC2QNa0U29qUolUCv1HzuRk2SG9ihHwqP62UBof0XJRQjGeLgUYAYh5YNH 7s0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uXotc14E; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id n14-20020a05640206ce00b0052a08b8f4fbsi5335189edy.269.2023.09.03.18.26.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Sep 2023 18:26:48 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uXotc14E; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 740CE385770A for ; Mon, 4 Sep 2023 01:26:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 740CE385770A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693790800; bh=kp4q0aYVl2iQxHfLtiYFMhDy1ZHTgpendjArvWI7ExE=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=uXotc14EON1lWaUweGjT7yCuegaLAg6rzFXeYuglM5Q4eKrFcknzAc3SN22Sb0nvG wLJFtJlJDuNigymbqyXcETq0z1d5iYvZ0vAXc/x9umtvoCeWEJjuhd2of5xOxUjcG2 anlVNLjFCQdLAScWRBmC8/sPSrMiAIB7onqydIok= 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 3CDBE3858D33 for ; Mon, 4 Sep 2023 01:25:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3CDBE3858D33 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 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) 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 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 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: 1776068390574347581 X-GMAIL-MSGID: 1776068390574347581 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" } } */