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 B05043858014 for ; Fri, 19 Nov 2021 06:33:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B05043858014 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 1AJ5l5D3030437 for ; Thu, 18 Nov 2021 22:33:21 -0800 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3cdvprtag1-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 18 Nov 2021 22:33:21 -0800 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.18; Thu, 18 Nov 2021 22:33:19 -0800 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.18 via Frontend Transport; Thu, 18 Nov 2021 22:33:19 -0800 Received: from linux.wrightpinski.org.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id 8DA923F706A; Thu, 18 Nov 2021 22:33:18 -0800 (PST) From: To: CC: Andrew Pinski Subject: [PATCH] Fix tree-optimization/103314 : Limit folding of (type) X op CST where type is a nop convert to gimple Date: Thu, 18 Nov 2021 22:33:13 -0800 Message-ID: <1637303593-31949-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: 1cHneFHzkkgEP06SXEgFgREm48LBrQ-T X-Proofpoint-GUID: 1cHneFHzkkgEP06SXEgFgREm48LBrQ-T 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-19_07,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: Fri, 19 Nov 2021 06:33:24 -0000 From: Andrew Pinski There is some re-association code in fold_binary which conflicts with this optimization due keeping around some "constants" which are not INTEGER_CST (1 << -1) so we end up in an infinite loop because of that. So we need to limit this case to GIMPLE level only. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/103314 gcc/ChangeLog: * match.pd ((type) X op CST): Restrict the equal TYPE_PRECISION case to GIMPLE only. gcc/testsuite/ChangeLog: * gcc.c-torture/compile/pr103314-1.c: New test. --- gcc/match.pd | 6 +++++- gcc/testsuite/gcc.c-torture/compile/pr103314-1.c | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr103314-1.c diff --git a/gcc/match.pd b/gcc/match.pd index 4dc66fb47f2..24a84e3b504 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1619,7 +1619,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) 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) + TYPE_PRECISION (TREE_TYPE (@0)) < TYPE_PRECISION (type) + /* The conversion check for being a nop can only be done at the gimple + level as fold_binary has some re-association code which can conflict + with this if there is a "constant" which is not a full INTEGER_CST. */ + || (GIMPLE && 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.c-torture/compile/pr103314-1.c b/gcc/testsuite/gcc.c-torture/compile/pr103314-1.c new file mode 100644 index 00000000000..f4a63130421 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr103314-1.c @@ -0,0 +1,6 @@ +/* { dg-options "" } */ +int main() { + int t = 1; + unsigned c = 0, d1 = t ? 1 ^ c ^ 1 >> (-1) : 0; /* { dg-warning "is negative" } */ + return d1; +} -- 2.17.1