]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/106533 - loop distribution of inner loop of nest
authorRichard Biener <rguenther@suse.de>
Fri, 5 Aug 2022 08:40:18 +0000 (10:40 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 5 Aug 2022 10:11:46 +0000 (12:11 +0200)
Loop distribution currently gives up if the outer loop of a loop
nest it analyzes contains a stmt with side-effects instead of
continuing to analyze the innermost loop.  The following fixes that
by continuing anyway.

PR tree-optimization/106533
* tree-loop-distribution.cc (loop_distribution::execute): Continue
analyzing the inner loops when find_seed_stmts_for_distribution
fails.

* gcc.dg/tree-ssa/ldist-39.c: New testcase.

gcc/testsuite/gcc.dg/tree-ssa/ldist-39.c [new file with mode: 0644]
gcc/tree-loop-distribution.cc

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ldist-39.c b/gcc/testsuite/gcc.dg/tree-ssa/ldist-39.c
new file mode 100644 (file)
index 0000000..3ef7286
--- /dev/null
@@ -0,0 +1,16 @@
+/* PR/106533 */
+/* { dg-options "-O2 -fdump-tree-ldist-optimized" } */
+
+void bar (int *a, int * __restrict b)
+{
+  for (int k = 0; k < 10; k++)
+    {
+      for (int j = 0; j < 100000; ++j)
+       a[j] = b[j];
+      __builtin_printf ("Foo!");
+    }
+}
+
+/* The stmt with side-effects in the outer loop should not prevent
+   distribution of the inner loop of the loop nest.  */
+/* { dg-final { scan-tree-dump "optimized: Loop . distributed: split to 0 loops and 1 library calls" "ldist" } } */
index 0ee441c077d07c1192f74585f46206d1b5049971..e1948fb452a72c3a8bb842cd70ebddc8f487a9cf 100644 (file)
@@ -3829,7 +3829,7 @@ loop_distribution::execute (function *fun)
        {
          auto_vec<gimple *> work_list;
          if (!find_seed_stmts_for_distribution (loop, &work_list))
-           break;
+           continue;
 
          const char *str = loop->inner ? " nest" : "";
          dump_user_location_t loc = find_loop_location (loop);