public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-7469] tree-optimization/110298 - CFG cleanup and stale nb_iterations
Date: Fri, 23 Jun 2023 10:30:11 +0000 (GMT)	[thread overview]
Message-ID: <20230623103011.2B29F3857704@sourceware.org> (raw)

https://gcc.gnu.org/g:9da2ef362fa8dc54df26c704a38dda40baee3ce9

commit r13-7469-g9da2ef362fa8dc54df26c704a38dda40baee3ce9
Author: Richard Biener <rguenther@suse.de>
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 ddc31a82fdc..9dc4ee4ca72 100644
--- a/gcc/tree-ssa-loop-ivcanon.cc
+++ b/gcc/tree-ssa-loop-ivcanon.cc
@@ -1486,15 +1486,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);
 	}

                 reply	other threads:[~2023-06-23 10:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230623103011.2B29F3857704@sourceware.org \
    --to=rguenth@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).