From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id B0E243858D32 for ; Sun, 17 Sep 2023 21:41:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B0E243858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=marvell.com 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 38HLYB53004170 for ; Sun, 17 Sep 2023 14:41:09 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=mkYU1Bo+FGP67kkZPUs+KoDlxCWMC0m1WV8t2nquBK0=; b=jSAabiOnFbztEfXfVA8tlXq3JKZCK2E16Zm/t1oe31TYTUrJxolOSxmwgtO/8mi2UZr3 DBdh9uZboSANrkfGaH8w2a1RR484jvxAXcE/roL37B+i6AIEfuBxPAdqRpXqqAjw2ogT lU6po04CZe8dSCfZriuH0fH5p9AMgITYQ/cfgJw4hgMGzyii4rU0oNzVflXtm2ionOl7 VHob0cKVPNY6Oo+2WrOezOasGrrQpkXt1USX80gXn6XBWY5d9r+1Ug/s1Q40wYBq4w2p 8OzECrOACEpsmca/qOCXS60q7EYmtCJUpU0+0qaMpYABQ1+/EbRZBzUB9xCBwrKOMAOj /w== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3t5bvkj8j9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sun, 17 Sep 2023 14:41:09 -0700 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.48; Sun, 17 Sep 2023 14:41:07 -0700 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.48 via Frontend Transport; Sun, 17 Sep 2023 14:41:07 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 344995C68F6; Sun, 17 Sep 2023 14:41:07 -0700 (PDT) From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH] MATCH: Make zero_one_valued_p non-recusive fully Date: Sun, 17 Sep 2023 14:40:55 -0700 Message-ID: <20230917214055.1752964-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: DybDflu79OOnAzwpyWpbDSfwXCeYUrQO X-Proofpoint-ORIG-GUID: DybDflu79OOnAzwpyWpbDSfwXCeYUrQO 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_20,2023-09-15_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 List-Id: So it turns out VN can't handle any kind of recusion for match. In this case we have `b = a & -1` and we try to match a as being zero_one_valued_p and VN returns b as being the value and we just go into an infinite loop at this point. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. Note genmatch should warn (or error out) if this gets detected so I filed PR 111446 which I will be looking into next week or the week after so we don't run into this issue again. PR tree-optimization/111442 gcc/ChangeLog: * match.pd (zero_one_valued_p): Have the bit_and match not be recusive. gcc/testsuite/ChangeLog: * gcc.c-torture/compile/pr111442-1.c: New test. --- gcc/match.pd | 5 ++++- gcc/testsuite/gcc.c-torture/compile/pr111442-1.c | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr111442-1.c diff --git a/gcc/match.pd b/gcc/match.pd index 887665633d4..773c3810f51 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2183,8 +2183,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* (a&1) is always [0,1] too. This is useful again when the range is not known. */ +/* Note this can't be recusive due to VN handling of equivalents, + VN and would cause an infinite recusion. */ (match zero_one_valued_p - (bit_and:c@0 @1 zero_one_valued_p)) + (bit_and:c@0 @1 integer_onep) + (if (INTEGRAL_TYPE_P (type)))) /* 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 */ diff --git a/gcc/testsuite/gcc.c-torture/compile/pr111442-1.c b/gcc/testsuite/gcc.c-torture/compile/pr111442-1.c new file mode 100644 index 00000000000..5814ee938de --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr111442-1.c @@ -0,0 +1,13 @@ + +int *a, b; +int main() { + int d = 1, e; + if (d) + e = a ? 0 % 0 : 0; + if (d) + a = &d; + d = -1; + b = d & e; + b = 2 * e ^ 1; + return 0; +} -- 2.31.1