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 r11-8462] tree-optimization/100492 - avoid irreducible regions in loop distribution
Date: Tue, 25 May 2021 08:07:12 +0000 (GMT)	[thread overview]
Message-ID: <20210525080712.54C80384782A@sourceware.org> (raw)

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

commit r11-8462-g9b3852d998bd4ae68f51311441feea13103971e3
Author: Richard Biener <rguenther@suse.de>
Date:   Mon May 10 11:37:27 2021 +0200

    tree-optimization/100492 - avoid irreducible regions in loop distribution
    
    When we distribute away a condition we rely on the ability to
    change it to either 1 != 0 or 0 != 0 depending on the direction
    of the exit branch in the respective loop.  But when the loop
    contains an irreducible sub-region then for the conditions inside
    this this fails and can lead to infinite loops being generated.
    
    Avoid distibuting loops with irreducible sub-regions.
    
    2021-05-10  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/100492
            * tree-loop-distribution.c (find_seed_stmts_for_distribution):
            Find nothing when the loop contains an irreducible region.
    
            * gcc.dg/torture/pr100492.c: New testcase.
    
    (cherry picked from commit 60af2db18013a0339302928ba98fee893ccc1957)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr100492.c | 26 ++++++++++++++++++++++++++
 gcc/tree-loop-distribution.c            | 10 ++++++++++
 2 files changed, 36 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/torture/pr100492.c b/gcc/testsuite/gcc.dg/torture/pr100492.c
new file mode 100644
index 00000000000..75229c8813b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr100492.c
@@ -0,0 +1,26 @@
+/* { dg-do run } */
+/* { dg-additional-options "-ftree-loop-distribution" } */
+
+extern void abort (void);
+
+signed char a, c;
+int b, d, *e = &d, g;
+signed static char f;
+int main() {
+  int h = 0;
+  int a_ = a;
+  for (; a_ < 1; a = ++a_) {
+    int *i[5], **j = &i[4], ***k[3][2] = {{&j}}, ****l = &k[2][1], *****m = &l;
+    char *n = &c;
+    f = *e = g = 0;
+    for (; g < 2; g++) {
+      for (b = 0; b < 3; b++)
+        h = (h && (*n = 0)) == 0;
+      if (g)
+        break;
+    }
+  }
+  if (f != 0)
+    abort ();
+  return 0;
+}
diff --git a/gcc/tree-loop-distribution.c b/gcc/tree-loop-distribution.c
index 8b91a30d1c6..65aa1df4aba 100644
--- a/gcc/tree-loop-distribution.c
+++ b/gcc/tree-loop-distribution.c
@@ -3203,6 +3203,16 @@ find_seed_stmts_for_distribution (class loop *loop, vec<gimple *> *work_list)
   /* Initialize the worklist with stmts we seed the partitions with.  */
   for (unsigned i = 0; i < loop->num_nodes; ++i)
     {
+      /* In irreducible sub-regions we don't know how to redirect
+	 conditions, so fail.  See PR100492.  */
+      if (bbs[i]->flags & BB_IRREDUCIBLE_LOOP)
+	{
+	  if (dump_file && (dump_flags & TDF_DETAILS))
+	    fprintf (dump_file, "loop %d contains an irreducible region.\n",
+		     loop->num);
+	  work_list->truncate (0);
+	  break;
+	}
       for (gphi_iterator gsi = gsi_start_phis (bbs[i]);
 	   !gsi_end_p (gsi); gsi_next (&gsi))
 	{


                 reply	other threads:[~2021-05-25  8:07 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=20210525080712.54C80384782A@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).