From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id D929B384AB58; Wed, 24 Apr 2024 08:13:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D929B384AB58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1713946389; bh=FWUpfkX4+Yo84Ul2W380yzJzvmwCyipv30hlhnYSPGQ=; h=From:To:Subject:Date:From; b=qgB2vW9/BGtpNoh0mfoxhVQMFpfqYBdxMBFmnzheelotgzXmTM7XLgIU5M5JRXbh3 ep/l2udCbszaAjOa2Sg4QVMyeAJ5fMi5zzbDVMbVD9gxa5I6zMLKvzjRQFRJeXuogH oaOzMQxki2dDE3uDPB+k8WLWIX+5Ngd+9hkiIGK8= 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 r14-10106] tree-optimization/114787 - more careful loop update with CFG cleanup X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: e28e8ab1a92e9b49f7c4045377577c8dc17751b7 X-Git-Newrev: cc48418cfc2e555d837ae9138cbfac23acb3cdf9 Message-Id: <20240424081309.D929B384AB58@sourceware.org> Date: Wed, 24 Apr 2024 08:13:09 +0000 (GMT) List-Id: https://gcc.gnu.org/g:cc48418cfc2e555d837ae9138cbfac23acb3cdf9 commit r14-10106-gcc48418cfc2e555d837ae9138cbfac23acb3cdf9 Author: Richard Biener Date: Wed Apr 24 08:42:40 2024 +0200 tree-optimization/114787 - more careful loop update with CFG cleanup When CFG cleanup removes a backedge we have to be more careful with loop update. In particular we need to clear niter info and estimates and if we remove the last backedge of a loop we have to also mark it for removal to prevent a following basic block merging to associate loop info with an unrelated header. PR tree-optimization/114787 * tree-cfg.cc (remove_edge_and_dominated_blocks): When removing a loop backedge clear niter info and when removing the last backedge of a loop mark that loop for removal. * gcc.dg/torture/pr114787.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/torture/pr114787.c | 27 +++++++++++++++++++++++++++ gcc/tree-cfg.cc | 26 +++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/gcc/testsuite/gcc.dg/torture/pr114787.c b/gcc/testsuite/gcc.dg/torture/pr114787.c new file mode 100644 index 00000000000..1c7294bee7b --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr114787.c @@ -0,0 +1,27 @@ +/* { dg-do run } */ + +int a, b, c, d, e = -1, f, g, h, j, k, n, o, p; +int main() { + int i, l = 2, m; + for (b = 0; b < 1; b++) + l = 0; + for (; a >= 0; a--) + for (m = 3; m; m--) { + k = g; + i = 0; + for (; i < 1; i++) + for (; f < 1; f++) + h = g; + n = 2 & ((e ^ d) | 1) * j; + o = ~(e & n); + q: + if (c <= e) + return 0; + e = o; + } + p = l; + l = 0; + if (p) + goto q; + return 0; +} diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index d98b68d6787..b1ba33018fd 100644 --- a/gcc/tree-cfg.cc +++ b/gcc/tree-cfg.cc @@ -9013,10 +9013,30 @@ remove_edge_and_dominated_blocks (edge e) /* If we are removing a path inside a non-root loop that may change loop ownership of blocks or remove loops. Mark loops for fixup. */ + class loop *src_loop = e->src->loop_father; if (current_loops - && loop_outer (e->src->loop_father) != NULL - && e->src->loop_father == e->dest->loop_father) - loops_state_set (LOOPS_NEED_FIXUP); + && loop_outer (src_loop) != NULL + && src_loop == e->dest->loop_father) + { + loops_state_set (LOOPS_NEED_FIXUP); + /* If we are removing a backedge clear the number of iterations + and estimates. */ + class loop *dest_loop = e->dest->loop_father; + if (e->dest == src_loop->header + || (e->dest == dest_loop->header + && flow_loop_nested_p (dest_loop, src_loop))) + { + free_numbers_of_iterations_estimates (dest_loop); + /* If we removed the last backedge mark the loop for removal. */ + FOR_EACH_EDGE (f, ei, dest_loop->header->preds) + if (f != e + && (f->src->loop_father == dest_loop + || flow_loop_nested_p (dest_loop, f->src->loop_father))) + break; + if (!f) + mark_loop_for_removal (dest_loop); + } + } if (!dom_info_available_p (CDI_DOMINATORS)) {