From patchwork Fri Sep 15 01:08:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 139952 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp728617vqi; Thu, 14 Sep 2023 18:09:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGUxVEJ0aJ87+3U98J1Pyvoj/UvR/l6fbs7F5DKga9FwuWcMzOQrhIvdyJA6CeEyIHd3gvw X-Received: by 2002:a05:6402:164b:b0:523:2e63:b9b with SMTP id s11-20020a056402164b00b005232e630b9bmr143794edx.24.1694740196392; Thu, 14 Sep 2023 18:09:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694740196; cv=none; d=google.com; s=arc-20160816; b=azcYvbuWlHtoSDzL8jebhF00WHsK41/7QMK4NMnMrvejutBMqlb+gpkXIno3ZWlqu9 l9Q/CZSrN0Mp5zNTCKEr1IP7wGndnslhlEqfPxnEQ4RnPGjluVYoHJb3ll/BkWPrdzqw e4+kUfG8fR32dcs2dNjNRyefXlspremqKAr8B8YwVDfL15OaynP8dLHjCRBf/DCr9FhW e2zL5suPsGrwOoUe/+7o09o2ZmqaszyIMwLn2Fx8TJBSvv9rYDDpIw5JNz/P6t7zJwkL 1KKJTTGDuQw7ep6jeudzON54CPAYM/WlRf+ZH67XuHNwZY8sMoNqNeNT9wPCqC2oRtCD YE3w== 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=v7IET3TNLocfi8LrLZYFNg4s24b2rCOQygclHnZSvb8=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=iILIQy3LDF0GyqiJuYwnBWIrX6dObpPVwa6hl187YzDy0LNcS1VNp0X1R2gfXuDvk7 3+BJCB9y3VWg4xSxC7GOxGZFnPlPvbw3wktWjTlrMnhl5dV2YUFfEcwrUiYs1/LSTzdS HSOuhSuYPGg4KvFmvRLn4vgbJwdaOdkQv+1wQ4UCnEwydw4IzLL5suDSBtcSJwPgGGWw SAjSThtUSLehBTUAmAmfa0f4q+VF2QZH7h11V7dgIH6yKxvlflYd36TptnC0Lc76cBn1 WjDh/pLKhFQpXSD0Q9jc1b1YgUhq+hXci6LzEAObeMOme/i8bVdIdQScSexpPyAMHrlB 2RrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ZXNbafGl; 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 r4-20020a056402034400b005234945a7d4si2386163edw.531.2023.09.14.18.09.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 18:09:56 -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=ZXNbafGl; 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 A3A423858C27 for ; Fri, 15 Sep 2023 01:09:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3A423858C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694740194; bh=v7IET3TNLocfi8LrLZYFNg4s24b2rCOQygclHnZSvb8=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=ZXNbafGlgsw5pWjjl1dhlUizg5CDrKKnDzKfONPP7b6pGasgMdFr2RG6HjP1IBLAb 7Czu43z6GSejsLqQzAslD5cSFPAP8Q/K0mqkjLOV4ppbochFKLISSDpA3tugtkSl4L 3dfsA5w5pOdBFQg8zD3qUR/PF3XsTpHJwqytp0qY= 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 C95963858CDA for ; Fri, 15 Sep 2023 01:09:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C95963858CDA 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 38F0GbcD028334 for ; Thu, 14 Sep 2023 18:09:07 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3t2y86aqe0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 14 Sep 2023 18:09:07 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Thu, 14 Sep 2023 18:09:05 -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; Thu, 14 Sep 2023 18:09:05 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 00BCE5B692C; Thu, 14 Sep 2023 18:09:04 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] MATCH: Improve zero_one_valued_p for cases without range information Date: Thu, 14 Sep 2023 18:08:55 -0700 Message-ID: <20230915010855.1582726-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: s0skEgC1C7eMKTccpW5CSijOuQiyLYLk X-Proofpoint-GUID: s0skEgC1C7eMKTccpW5CSijOuQiyLYLk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-15_01,2023-09-14_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: 1777063896617103098 X-GMAIL-MSGID: 1777063896617103098 I noticed we sometimes lose range information in forwprop due to a few match and simplify patterns optimizing away casts. So the easier way to these cases is to add a match for zero_one_valued_p wich mathes a cast from another zero_one_valued_p. This also adds the case of `x & zero_one_valued_p` as being zero_one_valued_p which allows catching more cases too. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * match.pd (zero_one_valued_p): Match a cast from a zero_one_valued_p. Also match `a & zero_one_valued_p` too. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/bool-13.c: Update testcase as we now do the MIN/MAX during forwprop1. --- gcc/match.pd | 10 ++++++++++ gcc/testsuite/gcc.dg/tree-ssa/bool-13.c | 15 +++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index 97db0eb5f25..39c9c81966a 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2181,6 +2181,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && (TYPE_UNSIGNED (type) || TYPE_PRECISION (type) > 1)))) +/* (a&1) is always [0,1] too. This is useful again when + the range is not known. */ +(match zero_one_valued_p + (bit_and:c@0 @1 zero_one_valued_p)) + +/* A conversion from an zero_one_valued_p is still a [0,1]. + This is useful when the range of a variable is not known */ +(match zero_one_valued_p + (convert@0 zero_one_valued_p)) + /* Transform { 0 or 1 } * { 0 or 1 } into { 0 or 1 } & { 0 or 1 }. */ (simplify (mult zero_one_valued_p@0 zero_one_valued_p@1) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bool-13.c b/gcc/testsuite/gcc.dg/tree-ssa/bool-13.c index 438f15a484a..de8c99a7727 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/bool-13.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/bool-13.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O1 -fdump-tree-optimized -fdump-tree-original -fdump-tree-phiopt1 -fdump-tree-forwprop2" } */ +/* { dg-options "-O1 -fdump-tree-optimized -fdump-tree-original -fdump-tree-forwprop1 -fdump-tree-forwprop2" } */ #define bool _Bool int maxbool(bool ab, bool bb) { @@ -22,15 +22,10 @@ int minbool(bool ab, bool bb) /* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "original" } } */ /* { dg-final { scan-tree-dump-times "if " 0 "original" } } */ -/* PHI-OPT1 should have kept it as min/max. */ -/* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "phiopt1" } } */ -/* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "phiopt1" } } */ -/* { dg-final { scan-tree-dump-times "if " 0 "phiopt1" } } */ - -/* Forwprop2 (after ccp) will convert it into &\| */ -/* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "forwprop2" } } */ -/* { dg-final { scan-tree-dump-times "MIN_EXPR" 0 "forwprop2" } } */ -/* { dg-final { scan-tree-dump-times "if " 0 "forwprop2" } } */ +/* Forwprop1 will convert it into &\| as we can detect that the arguments are one_zero. */ +/* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 0 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "if " 0 "forwprop1" } } */ /* By optimize there should be no min/max nor if */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "optimized" } } */