From patchwork Sat Nov 26 16:41:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 26278 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp4725865wrr; Sat, 26 Nov 2022 08:42:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf6zXuGsuP2basMV/LnOcAfNSf6YmS+4Dz1Wzs14c1pcna+lS9PQ474i82SOoKJhoZxPPBI5 X-Received: by 2002:a17:907:7f8e:b0:7bb:52b2:4162 with SMTP id qk14-20020a1709077f8e00b007bb52b24162mr11257832ejc.608.1669480964087; Sat, 26 Nov 2022 08:42:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669480964; cv=none; d=google.com; s=arc-20160816; b=MXWmwca6QDBa2GUvAGAokBS8zC8T/ILB2502eipzpkIdhVy43dLOrYmn5uC9zjwuc4 i6ccoAqmvkdwgUj420v2sUT1Lf+ZeXynr1p+e4mnSxN/Obx6vQ5iRgE09A29h8GbgYNq KfVETxkGdITGCSB02zRSs27E1sC6XLlu/xz4ZozEim53F6Gi4Yp/FM2lnCSgIGUc3bAH 8LUUW6qKP8cYTIuJVHy5vJUiRaxkjHhsx9ib66tT+WOCyIhCd9pVPpD5zGlf2nVVpEG3 l+wvSeh68c5FMURfywTS6z5o3+rxEWoueKy4VJkYbHG5NX4M4453yPz2NnncDWM6ayXl 4d+Q== 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:mime-version :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=M6asRXkI0PQTSKq8U2nGnv+sq3thvJBWke+fMosNVCY=; b=UxTu0LkG5Zbc2p2TIFSygGkAj6T3TpwmsrVvT5CmCmk2/gYb1Zf7GkKiaLX2mqSthI APrFLmqMvcTo6J9nyObgT/wiu+eOL6v8z2MALdjNBx+xjXGUrZ1ngvE4/DErq6j5bgPC Rk5JHvchV1WbR0Z1rK/NBK9s/FF7lLMojW2hkoX/tXQs3//aoKcEWKQ1Fq3GYLZHh1od hWVvMgYUoZZNFZZSTgN6SbKQPhyK0xHJxpal6J/7Jz2AtEPw1rhNttHyEvArVMu6OC/g yquPkAXmqsjMZmjL3d5aI0LeeQEMebHF5bEGRyeiPODBegTAmkRvue4j3tbBr2e+mdom tvpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gyDYXLtl; 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 sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id c7-20020aa7c747000000b00461cd4b5a01si5330417eds.419.2022.11.26.08.42.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Nov 2022 08:42:44 -0800 (PST) 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=gyDYXLtl; 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 1A94C384E3A7 for ; Sat, 26 Nov 2022 16:42:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A94C384E3A7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669480963; bh=M6asRXkI0PQTSKq8U2nGnv+sq3thvJBWke+fMosNVCY=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=gyDYXLtle3U2EbwOhc5ODhPg7LzXbkMwAygKXnPfhTUS3LkOoqbzNWB2fgaQ7EiSm oTzJ8v1mWNO1sok8rD3CIWlVHP54WQLpOvIqoiCpQuSG2n3Bpuq3Y/cgpT21t8MBkn LNmJDjijz/W6kFRmTvzUqmrpMP3zHyxz/Vm1ZleI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 1EDE5385B53B for ; Sat, 26 Nov 2022 16:41:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1EDE5385B53B Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AQFTeRw022229 for ; Sat, 26 Nov 2022 08:41:56 -0800 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3m3h1vgkgf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 26 Nov 2022 08:41:55 -0800 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.2; Sat, 26 Nov 2022 08:41:54 -0800 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.2 via Frontend Transport; Sat, 26 Nov 2022 08:41:54 -0800 Received: from linux.wrightpinski.org.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id 9DC3A3F709B; Sat, 26 Nov 2022 08:41:53 -0800 (PST) To: CC: Andrew Pinski Subject: [PATCH] tree-optimization/103356 Add missing (~a) == b folding for _Bool Date: Sat, 26 Nov 2022 08:41:38 -0800 Message-ID: <1669480898-21885-1-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Proofpoint-GUID: 3ay4142ULykSuuu1aSXJr_BexBhixV5B X-Proofpoint-ORIG-GUID: 3ay4142ULykSuuu1aSXJr_BexBhixV5B X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-26_12,2022-11-25_01,2022-06-22_01 X-Spam-Status: No, score=-14.5 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_NONE, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: apinski--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: apinski@marvell.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750577671299089093?= X-GMAIL-MSGID: =?utf-8?q?1750577671299089093?= From: Andrew Pinski The following makes sure to fold (~a) == b to a ^ b for truth values. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. Thanks, Andrew Pinski PR 103356 gcc/ChangeLog: * match.pd: ((~a) == b -> a ^ b): New pattern. gcc/testsuite/ChangeLog: * gcc.dg/pr103356-1.c: New test. --- gcc/match.pd | 7 +++++++ gcc/testsuite/gcc.dg/pr103356-1.c | 9 +++++++++ 2 files changed, 16 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr103356-1.c diff --git a/gcc/match.pd b/gcc/match.pd index a4d1386fd9f..67a0a682f31 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1999,6 +1999,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && TYPE_PRECISION (TREE_TYPE (@0)) == 1) (convert (eq @0 @1)))) +/* (~a) == b is a ^ b for truth valued a and b. */ +(simplify + (eq:c (bit_not:s truth_valued_p@0) truth_valued_p@1) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && TYPE_PRECISION (TREE_TYPE (@0)) == 1) + (convert (bit_xor @0 @1)))) + /* (x & ~m) | (y & m) -> ((x ^ y) & m) ^ x */ (simplify (bit_ior:c (bit_and:cs @0 (bit_not @2)) (bit_and:cs @1 @2)) diff --git a/gcc/testsuite/gcc.dg/pr103356-1.c b/gcc/testsuite/gcc.dg/pr103356-1.c new file mode 100644 index 00000000000..61d0b81da22 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr103356-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-forwprop1" } */ + +_Bool foo (_Bool a, _Bool b) +{ + return a == (!b); +} + +/* { dg-final { scan-tree-dump "\[ab\]_\[0-9\]+\\(D\\) \\\^ \[ba\]_\[0-9\]+\\(D\\)" "forwprop1" } } */