From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1314) id BFBCD3858D32; Mon, 18 Sep 2023 20:45:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BFBCD3858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695069954; bh=/TVClRLJP3eHxYkjFJKqwmuqvSKPUwzuN2ozw+B+n4Q=; h=From:To:Subject:Date:From; b=QRIf0Hj+Yh+xl0LIekxwLQJX6UbqGDQJAam1DrY10BPPZerKOeoobSrgrC2BNmH43 NgiKX8RJcTRVrQb/ggEQ3PKShOMvgD7fk+YkJ/GL1KizuELtMzHiJ3sCopsAVXWg6I mol+iZj99YJkK6+64qwamb4bjzHOZZVyUpD/fpDI= 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-4113] MATCH: Avoid recursive zero_one_valued_p for conversions X-Act-Checkin: gcc X-Git-Author: Andrew Pinski X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 80968d5f4683ffb50dbe8051d10f754d5fd00dfb X-Git-Newrev: 951d3c191d01440ad54415f683437770b0c957e4 Message-Id: <20230918204554.BFBCD3858D32@sourceware.org> Date: Mon, 18 Sep 2023 20:45:54 +0000 (GMT) List-Id: https://gcc.gnu.org/g:951d3c191d01440ad54415f683437770b0c957e4 commit r14-4113-g951d3c191d01440ad54415f683437770b0c957e4 Author: Andrew Pinski Date: Sat Sep 16 15:19:58 2023 -0700 MATCH: Avoid recursive zero_one_valued_p for conversions So when VN finds a name which has a nop conversion, it says both names are equivalent to each other and the valuaization function for one will return the other. This normally does not cause any issues as there is no recursive matches. But after r14-4038-gb975c0dc3be285, there was one added. So we would do an infinite recursion on the match and never finish. This fixes the issue (and adds a comment in match.pd) by for converts just handle one level instead of being recursive always. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. Note the testcase was reduced from tree-ssa-loop-niter.cc and then changed slightly into C rather than C++ but it still needs exceptions turned on get the IR that VN would produce this equivalence relationship going on. Also had to turn off early inline to force put to be inlined later. PR tree-optimization/111435 gcc/ChangeLog: * match.pd (zero_one_valued_p): Don't do recursion on converts. gcc/testsuite/ChangeLog: * gcc.c-torture/compile/pr111435-1.c: New test. Diff: --- gcc/match.pd | 8 +++++++- gcc/testsuite/gcc.c-torture/compile/pr111435-1.c | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/gcc/match.pd b/gcc/match.pd index a05d4f07ab5..a405c9ff6f8 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2188,8 +2188,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* 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 */ +/* Note this matches can't be recursive because of the way VN handles + nop conversions being equivalent and then recursive between them. */ (match zero_one_valued_p - (convert@0 zero_one_valued_p)) + (convert@0 @1) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@1)) + && (TYPE_UNSIGNED (TREE_TYPE (@1)) + || TYPE_PRECISION (TREE_TYPE (@1)) > 1) + && wi::leu_p (tree_nonzero_bits (@1), 1)))) /* Transform { 0 or 1 } * { 0 or 1 } into { 0 or 1 } & { 0 or 1 }. */ (simplify diff --git a/gcc/testsuite/gcc.c-torture/compile/pr111435-1.c b/gcc/testsuite/gcc.c-torture/compile/pr111435-1.c new file mode 100644 index 00000000000..afa84dd59dd --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr111435-1.c @@ -0,0 +1,18 @@ +/* { dg-options "-fexceptions -fno-early-inlining" } */ +/* { dg-require-effective-target exceptions } */ + +void find_slot_with_hash(const int *); + +void put(const int *k, const int *) { + find_slot_with_hash(k); +} +unsigned len(); +int *address(); +void h(int header, int **bounds) { + if (!*bounds) + return; + unsigned t = *bounds ? len() : 0; + int queue_index = t; + address()[(unsigned)queue_index] = 0; + put(&header, &queue_index); +}