]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/106055 - issue with autopar
authorRichard Biener <rguenther@suse.de>
Fri, 1 Jul 2022 13:32:30 +0000 (15:32 +0200)
committerRichard Biener <rguenther@suse.de>
Mon, 4 Jul 2022 07:09:45 +0000 (09:09 +0200)
When autopar uses graphites canonicalize_loop_closed_ssa it fails to
check whether propagation is allowed and thus it ends up messing up
abnormal constraints.

2022-07-01  Richard Biener  <rguenther@suse.de>

PR tree-optimization/106055
* graphite.cc (canonicalize_loop_closed_ssa): Check whether
we can propagate.

* gcc.dg/graphite/pr106055.c: New testcase.

gcc/graphite.cc
gcc/testsuite/gcc.dg/graphite/pr106055.c [new file with mode: 0644]

index a88b13c021988c1253d081081b4fba3fdb87240f..fd4f7a126e17f119e50fadb5c96d649aefbdcfdc 100644 (file)
@@ -57,6 +57,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-ssa-loop-manip.h"
 #include "tree-ssa.h"
 #include "tree-into-ssa.h"
+#include "tree-ssa-propagate.h"
 #include "graphite.h"
 
 /* Print global statistics to FILE.  */
@@ -337,7 +338,9 @@ canonicalize_loop_closed_ssa (loop_p loop, edge e)
       /* Iterate over the next phis and remove duplicates.  */
       gsi_next (&gsi);
       while (!gsi_end_p (gsi))
-       if (gimple_phi_arg_def (phi, 0) == gimple_phi_arg_def (gsi.phi (), 0))
+       if (gimple_phi_arg_def (phi, 0) == gimple_phi_arg_def (gsi.phi (), 0)
+           && may_propagate_copy (gimple_phi_result (gsi.phi ()),
+                                  gimple_phi_result (phi)))
          {
            replace_uses_by (gimple_phi_result (gsi.phi ()),
                             gimple_phi_result (phi));
diff --git a/gcc/testsuite/gcc.dg/graphite/pr106055.c b/gcc/testsuite/gcc.dg/graphite/pr106055.c
new file mode 100644 (file)
index 0000000..22be62b
--- /dev/null
@@ -0,0 +1,41 @@
+/* { dg-do compile } */
+/* { dg-options "-Os -floop-parallelize-all -fno-tree-dce" } */
+
+__attribute__ ((returns_twice)) int
+bar (void);
+
+void
+quux (void);
+
+void
+empty (void)
+{
+}
+
+unsigned int
+choose (unsigned int x, unsigned int y)
+{
+  return y ? x : 0;
+}
+
+int
+foo (int *p, unsigned int x, int y)
+{
+  unsigned int acc = 0;
+
+  empty ();
+
+  while (x)
+    {
+      bar ();
+      ++x;
+    }
+
+  while (y)
+    acc += y;
+
+  *p = choose (acc, 1);
+  quux ();
+
+  return x;
+}