public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] tree-optimization/106521 - unroll-and-jam LC SSA rewrite
Date: Thu, 4 Aug 2022 10:49:56 +0000 (UTC)	[thread overview]
Message-ID: <20220804104956.JBB7qJlThdJES1iB4dftrKp9yeG8rEqOyLg3Vnm1nSY@z> (raw)

The LC SSA rewrite performs SSA verification at start but the VN
run performed on the unrolled-and-jammed body can leave us with
invalid SSA form until CFG cleanup is run.  So make sure we do that
before rewriting into LC SSA.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

	PR tree-optimization/106521
	* gimple-loop-jam.cc (tree_loop_unroll_and_jam): Perform
	CFG cleanup manually before rewriting into LC SSA.

	* gcc.dg/torture/pr106521.c: New testcase.
---
 gcc/gimple-loop-jam.cc                  |  8 ++++++++
 gcc/testsuite/gcc.dg/torture/pr106521.c | 17 +++++++++++++++++
 2 files changed, 25 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr106521.c

diff --git a/gcc/gimple-loop-jam.cc b/gcc/gimple-loop-jam.cc
index 8cde6c7c5ce..41ba4e42819 100644
--- a/gcc/gimple-loop-jam.cc
+++ b/gcc/gimple-loop-jam.cc
@@ -39,6 +39,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-ssa-loop-ivopts.h"
 #include "tree-vectorizer.h"
 #include "tree-ssa-sccvn.h"
+#include "tree-cfgcleanup.h"
 
 /* Unroll and Jam transformation
    
@@ -609,6 +610,13 @@ tree_loop_unroll_and_jam (void)
 
   if (todo)
     {
+      /* We need to cleanup the CFG first since otherwise SSA form can
+	 be not up-to-date from the VN run.  */
+      if (todo & TODO_cleanup_cfg)
+	{
+	  cleanup_tree_cfg ();
+	  todo &= ~TODO_cleanup_cfg;
+	}
       rewrite_into_loop_closed_ssa (NULL, 0);
       scev_reset ();
       free_dominance_info (CDI_DOMINATORS);
diff --git a/gcc/testsuite/gcc.dg/torture/pr106521.c b/gcc/testsuite/gcc.dg/torture/pr106521.c
new file mode 100644
index 00000000000..05c8ce54d0b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr106521.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-floop-unroll-and-jam --param unroll-jam-min-percent=0" } */
+
+short a, b, e;
+volatile long c;
+long d;
+int main() {
+  for (; d; d++) {
+    long g = a = 1;
+    for (; a; a++) {
+      g++;
+      c;
+    }
+    g && (b = e);
+  }
+  return 0;
+}
-- 
2.35.3

             reply	other threads:[~2022-08-04 10:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-04 10:49 Richard Biener [this message]
2022-08-04 10:49 Richard Biener
2022-08-04 10:49 Richard Biener

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=20220804104956.JBB7qJlThdJES1iB4dftrKp9yeG8rEqOyLg3Vnm1nSY@z \
    --to=rguenther@suse.de \
    --cc=gcc-patches@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).