From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id F25D9385B804; Fri, 12 Nov 2021 09:05:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F25D9385B804 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-5189] tree-optimization/103204 - fix missed valueization in VN X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: c60ded6f5eba1a2e5cd647928983d6a5fe46b64c X-Git-Newrev: 140346fa246dc2476c5c2bf2ecadebd18a3af5d0 Message-Id: <20211112090553.F25D9385B804@sourceware.org> Date: Fri, 12 Nov 2021 09:05:53 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Nov 2021 09:05:54 -0000 https://gcc.gnu.org/g:140346fa246dc2476c5c2bf2ecadebd18a3af5d0 commit r12-5189-g140346fa246dc2476c5c2bf2ecadebd18a3af5d0 Author: Richard Biener Date: Fri Nov 12 09:09:29 2021 +0100 tree-optimization/103204 - fix missed valueization in VN The following fixes a missed valueization when simplifying a MEM[&...] combination during valueization. 2021-11-12 Richard Biener PR tree-optimization/103204 * tree-ssa-sccvn.c (valueize_refs_1): Re-valueize the top operand after folding in an address. * gcc.dg/torture/pr103204.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/torture/pr103204.c | 16 ++++++++++++++++ gcc/tree-ssa-sccvn.c | 13 ++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/gcc/testsuite/gcc.dg/torture/pr103204.c b/gcc/testsuite/gcc.dg/torture/pr103204.c new file mode 100644 index 00000000000..b08b6864691 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr103204.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ + +int a[1][1]; +int b, c; +void d() +{ + int e; + int f[0]; + int *g; + for (; e;) + c = b; + if (a[0][b] = (__UINTPTR_TYPE__)f != 3) + g = &f[b]; + int h; + *g = *g = *g = h; +} diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 7be5d4e406f..149674e6a16 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -1640,13 +1640,12 @@ static void valueize_refs_1 (vec *orig, bool *valueized_anything, bool with_avail = false) { - vn_reference_op_t vro; - unsigned int i; - *valueized_anything = false; - FOR_EACH_VEC_ELT (*orig, i, vro) + for (unsigned i = 0; i < orig->length (); ++i) { +re_valueize: + vn_reference_op_t vro = &(*orig)[i]; if (vro->opcode == SSA_NAME || (vro->op0 && TREE_CODE (vro->op0) == SSA_NAME)) { @@ -1694,7 +1693,11 @@ valueize_refs_1 (vec *orig, bool *valueized_anything, && (*orig)[i - 1].opcode == MEM_REF) { if (vn_reference_maybe_forwprop_address (orig, &i)) - *valueized_anything = true; + { + *valueized_anything = true; + /* Re-valueize the current operand. */ + goto re_valueize; + } } /* If it transforms a non-constant ARRAY_REF into a constant one, adjust the constant offset. */