From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 254D33858438; Fri, 23 Jun 2023 11:30:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 254D33858438 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687519826; bh=yqs06+vsQBaTulH0DSAx2jLoS1YNWYb4xdrHccn/hbo=; h=From:To:Subject:Date:From; b=DBKzUnkvAL/OhDRv4aSGfT6UiKz23xAmy4VYhpqGpNldk71z86Sm/hvoRt4JqANli ViU1G7NBIFd5akjioYtZvVFfKVMXiDU41PcKV/Ca/UPYeomc5H77i9mYlfSa3b0NyO NSUqw8xr0ApZrcUpMiVwnaP9J8yvNojzFJkVSD6s= 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-9723] tree-optimization/110298 - CFG cleanup and stale nb_iterations X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: f06f1b4102b1c6965ad6b1da0094d6de5c3a2940 X-Git-Newrev: c409f2a1cc5d5bffe2fb93454924ae402c57f8f6 Message-Id: <20230623113026.254D33858438@sourceware.org> Date: Fri, 23 Jun 2023 11:30:26 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c409f2a1cc5d5bffe2fb93454924ae402c57f8f6 commit r12-9723-gc409f2a1cc5d5bffe2fb93454924ae402c57f8f6 Author: Richard Biener Date: Mon Jun 19 09:52:45 2023 +0200 tree-optimization/110298 - CFG cleanup and stale nb_iterations When unrolling we eventually kill nb_iterations info since it may refer to removed SSA names. But we do this only after cleaning up the CFG which in turn can end up accessing it. Fixed by swapping the two. PR tree-optimization/110298 * tree-ssa-loop-ivcanon.cc (tree_unroll_loops_completely): Clear number of iterations info before cleaning up the CFG. * gcc.dg/torture/pr110298.c: New testcase. (cherry picked from commit 916add3bf6e46467e4391e358b11ecfbc4daa275) Diff: --- gcc/testsuite/gcc.dg/torture/pr110298.c | 20 ++++++++++++++++++++ gcc/tree-ssa-loop-ivcanon.cc | 7 ++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/gcc/testsuite/gcc.dg/torture/pr110298.c b/gcc/testsuite/gcc.dg/torture/pr110298.c new file mode 100644 index 00000000000..139f5c77d89 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr110298.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ + +int a, b, c, d, e; +int f() { + c = 0; + for (; c >= 0; c--) { + d = 0; + for (; d <= 0; d++) { + e = 0; + for (; d + c + e >= 0; e--) + ; + a = 1; + b = 0; + for (; a; ++b) + a *= 2; + for (; b + d >= 0;) + return 0; + } + } +} diff --git a/gcc/tree-ssa-loop-ivcanon.cc b/gcc/tree-ssa-loop-ivcanon.cc index e2ac2044741..408916c7de0 100644 --- a/gcc/tree-ssa-loop-ivcanon.cc +++ b/gcc/tree-ssa-loop-ivcanon.cc @@ -1487,15 +1487,16 @@ tree_unroll_loops_completely (bool may_increase_size, bool unroll_outer) } BITMAP_FREE (fathers); + /* Clean up the information about numbers of iterations, since + complete unrolling might have invalidated it. */ + scev_reset (); + /* This will take care of removing completely unrolled loops from the loop structures so we can continue unrolling now innermost loops. */ if (cleanup_tree_cfg ()) update_ssa (TODO_update_ssa_only_virtuals); - /* Clean up the information about numbers of iterations, since - complete unrolling might have invalidated it. */ - scev_reset (); if (flag_checking && loops_state_satisfies_p (LOOP_CLOSED_SSA)) verify_loop_closed_ssa (true); }