]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/107302 - fix vec_perm placement for recurrence vect
authorRichard Biener <rguenther@suse.de>
Tue, 18 Oct 2022 08:01:45 +0000 (10:01 +0200)
committerRichard Biener <rguenther@suse.de>
Tue, 18 Oct 2022 10:49:23 +0000 (12:49 +0200)
The following fixes the VEC_PERM_EXPR placement when the latch
definition is a PHI node.

PR tree-optimization/107302
* tree-vect-loop.cc (vectorizable_recurrence): Fix vec_perm
placement for a PHI latch def.

* gcc.dg/vect/pr107302.c: New testcase.

gcc/testsuite/gcc.dg/vect/pr107302.c [new file with mode: 0644]
gcc/tree-vect-loop.cc

diff --git a/gcc/testsuite/gcc.dg/vect/pr107302.c b/gcc/testsuite/gcc.dg/vect/pr107302.c
new file mode 100644 (file)
index 0000000..293f7e4
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fno-tree-pre" } */
+
+int a[2000];
+int s292_im1;
+
+void
+s292() {
+  for (int i = 0; i < 2000; i++) {
+    a[i] = s292_im1;
+    s292_im1 = i;
+  }
+}
index 63e86540d12eb3e2e309d80f8b60f81ac82c1017..92790bd80953457dcb0fa0d056cca3bd62a3aaa7 100644 (file)
@@ -8485,9 +8485,15 @@ vectorizable_recurr (loop_vec_info loop_vinfo, stmt_vec_info stmt_info,
      second and later operands are tentative and will be updated when we have
      vectorized the latch definition.  */
   edge le = loop_latch_edge (LOOP_VINFO_LOOP (loop_vinfo));
-  gimple_stmt_iterator gsi2
-    = gsi_for_stmt (SSA_NAME_DEF_STMT (PHI_ARG_DEF_FROM_EDGE (phi, le)));
-  gsi_next (&gsi2);
+  gimple *latch_def = SSA_NAME_DEF_STMT (PHI_ARG_DEF_FROM_EDGE (phi, le));
+  gimple_stmt_iterator gsi2;
+  if (is_a <gphi *> (latch_def))
+    gsi2 = gsi_after_labels (gimple_bb (latch_def));
+  else
+    {
+      gsi2 = gsi_for_stmt (latch_def);
+      gsi_next (&gsi2);
+    }
 
   for (unsigned i = 0; i < ncopies; ++i)
     {