public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-7243] tree-optimization/104543 - fix unroll-and-jam precondition
@ 2022-02-15 12:22 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2022-02-15 12:22 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:d03a67dc69251dc86c0772a432380a6e9bcb8617

commit r12-7243-gd03a67dc69251dc86c0772a432380a6e9bcb8617
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Feb 15 12:27:14 2022 +0100

    tree-optimization/104543 - fix unroll-and-jam precondition
    
    We have to make sure that outer loop exits come after the inner
    loop since we otherwise will put it into the fused loop body.
    
    2022-02-15  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/104543
            * gimple-loop-jam.cc (unroll_jam_possible_p): Check outer loop exits
            come after the inner loop.
    
            * gcc.dg/torture/pr104543.c: New testcase.

Diff:
---
 gcc/gimple-loop-jam.cc                  | 10 ++++++++--
 gcc/testsuite/gcc.dg/torture/pr104543.c | 21 +++++++++++++++++++++
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/gcc/gimple-loop-jam.cc b/gcc/gimple-loop-jam.cc
index d9a77727665..e33dd9091df 100644
--- a/gcc/gimple-loop-jam.cc
+++ b/gcc/gimple-loop-jam.cc
@@ -198,7 +198,8 @@ unroll_jam_possible_p (class loop *outer, class loop *loop)
   if (!empty_block_p (loop->latch))
     return false;
 
-  if (!single_exit (loop))
+  edge exit;
+  if (!(exit = single_exit (loop)))
     return false;
 
   /* We need a perfect nest.  Quick check for adjacent inner loops.  */
@@ -259,7 +260,12 @@ unroll_jam_possible_p (class loop *outer, class loop *loop)
   n = get_loop_body_with_size (outer, bbs, n_basic_blocks_for_fn (cfun));
 
   for (i = 0; i < n; i++)
-    if (bbs[i]->loop_father == outer && bb_prevents_fusion_p (bbs[i]))
+    if (bbs[i]->loop_father == outer
+	&& (bb_prevents_fusion_p (bbs[i])
+	    /* Outer loop exits must come after the inner loop, otherwise
+	       we'll put the outer loop exit into the fused inner loop.  */
+	    || (loop_exits_from_bb_p (outer, bbs[i])
+		&& !dominated_by_p (CDI_DOMINATORS, bbs[i], exit->src))))
       break;
   free (bbs);
   if (i != n)
diff --git a/gcc/testsuite/gcc.dg/torture/pr104543.c b/gcc/testsuite/gcc.dg/torture/pr104543.c
new file mode 100644
index 00000000000..48963514f77
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr104543.c
@@ -0,0 +1,21 @@
+/* { dg-do run } */
+/* { dg-additional-options "-floop-unroll-and-jam" } */
+
+int a[3], b, c;
+static int e()
+{
+  if (!c) {
+    for (b = 0; b < 3; b++)
+      for (c = 0; c < 3; c++)
+        a[c] ^= 1;
+    return -1;
+  }
+  return 0;
+}
+int main()
+{
+  e();
+  if (a[1] != 1)
+    __builtin_abort();
+  return 0;
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-02-15 12:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-15 12:22 [gcc r12-7243] tree-optimization/104543 - fix unroll-and-jam precondition Richard Biener

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).