From patchwork Sat Nov 20 17:52:34 2021 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: 47975 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C7FDC3858411 for ; Sun, 21 Nov 2021 14:19:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C7FDC3858411 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637504375; bh=bSFkMh6hrfT9Ftu/lPrWi2PNSLKIFJWphZes7+CtNHQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=CoBr0KRZIa5jBNX3aX7N3e+QO70cUaQbVSuxjcSowtzWVY70+3ggZGFs5sookG8YJ CXVs/7iIQUHKinHI0f4Ts6l2Iwt2pRBDRwQSTfVYuq6ZnHWDfyahNZIcBPowaSbnzD dHw4LhMKWa6Wr+CXp0oxDGQiylf579UV9p1K0tFo= 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 8B3D93858406 for ; Sun, 21 Nov 2021 14:19:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8B3D93858406 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1ALDSPkt007289 for ; Sun, 21 Nov 2021 06:19:06 -0800 Received: from dc6wp-exch01.marvell.com ([4.21.29.232]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3cf1dtjx8g-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sun, 21 Nov 2021 06:19:05 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC6WP-EXCH01.marvell.com (10.76.176.21) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Sun, 21 Nov 2021 09:18:22 -0500 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.18; Sat, 20 Nov 2021 10:22:29 -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.18 via Frontend Transport; Sat, 20 Nov 2021 10:22:29 -0800 Received: from linux.wrightpinski.org.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id 2D2805B6ED3; Sat, 20 Nov 2021 09:52:37 -0800 (PST) To: Subject: [PATCH] tree-optimization: [PR31531] Improve ~a < CST, allow a nop cast inbetween ~ and a Date: Sat, 20 Nov 2021 09:52:34 -0800 Message-ID: <1637430754-23697-1-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: KF__SPfAxwbrhu7T4nR-RNArPIQsa2BZ X-Proofpoint-GUID: KF__SPfAxwbrhu7T4nR-RNArPIQsa2BZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-21_08,2021-11-17_01,2020-04-07_01 X-Spam-Status: No, score=-14.7 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 Cc: Andrew Pinski Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Andrew Pinski This PR was orignally for the missed optimization of a few isnegative which had been solved a long time ago (sometime before 4.4.0). I noticed there was one missed optimization on the gimple level. There is a match.pd pattern for ~a < CST but we miss that there could be a nop_convert between the the comparison and the bit_not. This adds the optional option cast to the current match.pd pattern. OK? Bootstrapped and tested on x86_64 with no regressions. PR tree-optimization/31531 gcc/ChangeLog: * match.pd (~X op C): Allow for an optional nop convert. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr31531-1.c: New test. --- gcc/match.pd | 5 +++-- gcc/testsuite/gcc.dg/tree-ssa/pr31531-1.c | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr31531-1.c diff --git a/gcc/match.pd b/gcc/match.pd index 37c5be9e5f4..ca6c9eff624 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4729,10 +4729,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (for cmp (simple_comparison) scmp (swapped_simple_comparison) (simplify - (cmp (bit_not@2 @0) CONSTANT_CLASS_P@1) + (cmp (nop_convert?:s (bit_not@2 @0)) CONSTANT_CLASS_P@1) (if (single_use (@2) && (TREE_CODE (@1) == INTEGER_CST || TREE_CODE (@1) == VECTOR_CST)) - (scmp @0 (bit_not @1))))) + (with { tree type1 = TREE_TYPE (@1); } + (scmp (convert:type1 @0) (bit_not @1)))))) (for cmp (simple_comparison) /* Fold (double)float1 CMP (double)float2 into float1 CMP float2. */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr31531-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr31531-1.c new file mode 100644 index 00000000000..c27299151eb --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr31531-1.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* PR tree-optimization/31531 */ + +int f(int a) +{ + int b = ~a; + return b<0; +} + + +int f1(unsigned a) +{ + int b = ~a; + return b<0; +} +/* We should convert the above two functions from b <0 to ((int)a) >= 0. */ +/* { dg-final { scan-tree-dump-times ">= 0" 2 "optimized"} } */ +/* { dg-final { scan-tree-dump-times "~" 0 "optimized"} } */