From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1314) id 121303857716; Mon, 18 Sep 2023 20:46:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 121303857716 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695069960; bh=HR0iKOH4Mbkgh0ATshur0e7rJBZRcWb8VLQw7/h5LU8=; h=From:To:Subject:Date:From; b=jvlQcmAwsecQQinXSlsrNRSvT5NqpSS5vwaIcYDyQupkqyj7FhMN88I+lXicpAUZL 76H5mSePdp+MvLF5KxwODz5Hp7LCakKi9X8U0/JV80e8QTGMufKCTQf43wUTb/c8Tk 2VSe/Dm+YSqYPCZOr06gqnBcOOIbMGHMV5RXCt2E= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Pinski To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-4114] MATCH: Make zero_one_valued_p non-recursive fully X-Act-Checkin: gcc X-Git-Author: Andrew Pinski X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 951d3c191d01440ad54415f683437770b0c957e4 X-Git-Newrev: 7ea501d3ea698e1c845fb61e3487f4cd949e6253 Message-Id: <20230918204600.121303857716@sourceware.org> Date: Mon, 18 Sep 2023 20:46:00 +0000 (GMT) List-Id: https://gcc.gnu.org/g:7ea501d3ea698e1c845fb61e3487f4cd949e6253 commit r14-4114-g7ea501d3ea698e1c845fb61e3487f4cd949e6253 Author: Andrew Pinski Date: Sun Sep 17 11:20:36 2023 -0700 MATCH: Make zero_one_valued_p non-recursive fully So it turns out VN can't handle any kind of recursion 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 recursive. gcc/testsuite/ChangeLog: * gcc.c-torture/compile/pr111442-1.c: New test. Diff: --- gcc/match.pd | 5 ++++- gcc/testsuite/gcc.c-torture/compile/pr111442-1.c | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gcc/match.pd b/gcc/match.pd index a405c9ff6f8..bef513aaa3f 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 recursive due to VN handling of equivalents, + VN and would cause an infinite recursion. */ (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; +}