From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id EE6233858402 for ; Wed, 17 Nov 2021 23:39:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EE6233858402 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1AHKuhMn018632 for ; Wed, 17 Nov 2021 15:39:45 -0800 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3cd34btph5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Wed, 17 Nov 2021 15:39:44 -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.18; Wed, 17 Nov 2021 15:39:31 -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; Wed, 17 Nov 2021 15:39:31 -0800 Received: from linux.wrightpinski.org.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id 56C2D3F707B; Wed, 17 Nov 2021 15:39:31 -0800 (PST) From: To: CC: Andrew Pinski Subject: [PATCH v2] Fix PR tree-optimization/103228 and 103228: folding of (type) X op CST where type is a nop convert Date: Wed, 17 Nov 2021 15:39:25 -0800 Message-ID: <1637192365-31563-1-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-ORIG-GUID: N8TcRcukyChxCPwsx_bR6WGqCp1TXVvz X-Proofpoint-GUID: N8TcRcukyChxCPwsx_bR6WGqCp1TXVvz 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-17_09,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-List-Received-Date: Wed, 17 Nov 2021 23:39:49 -0000 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. Committed as approved with the comment change. 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 | 6 ++++-- gcc/testsuite/gcc.dg/tree-ssa/pr103228-1.c | 11 +++++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr55177-1.c | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) 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 cd8f349f618..4dc66fb47f2 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1616,8 +1616,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) Restrict it to GIMPLE to avoid endless recursions. */ && (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) + after hoisting the conversion the operation will be narrower. + It is also a good if the conversion is a nop as moves the + conversion to one side; allowing for combining of the conversions. */ + 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"} } */ -- 2.17.1