From patchwork Tue Nov 16 03:35:11 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: 47745 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 3EBFF3858031 for ; Tue, 16 Nov 2021 03:35:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3EBFF3858031 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637033756; bh=dGsTHcCEBgS4PWWk6FXJuUQ/Om5bYKJiBVkLNr1T8Es=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=d370JKTqjnefJAllwI+241viRHOWgRhAm3RDKijqcorDaxz5Fq0gSwaS/FkFCGez1 mpX9lMebGgJaDYFIFMsvLS3YDxEmJ+BKjGlICzBk8BeKHvVgP17s8gKaFrJXfiCYc6 b8zlQnlOnSjZwSU/bjTa+7NtevziQDgktX9glwRM= 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 0DCCE3857809 for ; Tue, 16 Nov 2021 03:35:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0DCCE3857809 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 1AFJuP2n015069 for ; Mon, 15 Nov 2021 19:35:21 -0800 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3cbea8nepq-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 15 Nov 2021 19:35:21 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 15 Nov 2021 19:35:18 -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; Mon, 15 Nov 2021 19:35:18 -0800 Received: from linux.wrightpinski.org.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id DFDB93F7074; Mon, 15 Nov 2021 19:35:17 -0800 (PST) To: Subject: [PATCH] Fix PR tree-optimization/103228 and 103228: folding of (type) X op CST where type is a nop convert Date: Mon, 15 Nov 2021 19:35:11 -0800 Message-ID: <1637033711-17785-1-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Proofpoint-GUID: IsOXBMza0D71pFDHbKKbEVgMd6SXH7yM X-Proofpoint-ORIG-GUID: IsOXBMza0D71pFDHbKKbEVgMd6SXH7yM 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-15_16,2021-11-15_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 Currently we fold (type) X op CST into (type) (X op ((type-x) CST)) when the conversion widens but not when the conversion is a nop. For the same reason why we move the widening conversion (the possibility of removing an extra conversion), we should do the same if the conversion is a nop. OK? Boostrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/103228 PR tree-optimization/55177 gcc/ChangeLog: * match.pd ((type) X bitop CST): Also do this transformation for nop conversions. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr103228-1.c: New test. * gcc.dg/tree-ssa/pr55177-1.c: New test. --- gcc/match.pd | 2 +- gcc/testsuite/gcc.dg/tree-ssa/pr103228-1.c | 11 +++++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr55177-1.c | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr103228-1.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr55177-1.c diff --git a/gcc/match.pd b/gcc/match.pd index a0e9a82e4c4..dc3d5054583 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1615,7 +1615,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && (bitop != BIT_AND_EXPR || GIMPLE) && (/* That's a good idea if the conversion widens the operand, thus after hoisting the conversion the operation will be narrower. */ - TYPE_PRECISION (TREE_TYPE (@0)) < TYPE_PRECISION (type) + TYPE_PRECISION (TREE_TYPE (@0)) <= TYPE_PRECISION (type) /* It's also a good idea if the conversion is to a non-integer mode. */ || GET_MODE_CLASS (TYPE_MODE (type)) != MODE_INT diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr103228-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr103228-1.c new file mode 100644 index 00000000000..a7539819cf2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr103228-1.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +int f(int a, int b) +{ + b|=1u; + b|=2; + return b; +} +/* { dg-final { scan-tree-dump-times "\\\| 3" 1 "optimized"} } */ +/* { dg-final { scan-tree-dump-times "\\\| 1" 0 "optimized"} } */ +/* { dg-final { scan-tree-dump-times "\\\| 2" 0 "optimized"} } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr55177-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr55177-1.c new file mode 100644 index 00000000000..de1a264345c --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr55177-1.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +extern int x; + +void foo(void) +{ + int a = __builtin_bswap32(x); + a &= 0x5a5b5c5d; + x = __builtin_bswap32(a); +} + +/* { dg-final { scan-tree-dump-times "__builtin_bswap32" 0 "optimized"} } */ +/* { dg-final { scan-tree-dump-times "& 1566333786" 1 "optimized"} } */ +/* { dg-final { scan-tree-dump-times "& 1515936861" 0 "optimized"} } */