fix ICE with BB vectorization of PHIs
authorRichard Biener <rguenther@suse.de>
Fri, 9 Oct 2020 06:56:21 +0000 (08:56 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 9 Oct 2020 06:59:15 +0000 (08:59 +0200)
This fixes a vector CTOR insertion issue when we try to insert after
a PHI node.

2020-10-09  Richard Biener  <rguenther@suse.de>

* tree-vect-slp.c (vect_create_constant_vectors): Properly insert
after PHIs.

* gcc.dg/vect/bb-slp-phis-1.c: New testcase.

gcc/testsuite/gcc.dg/vect/bb-slp-phis-1.c [new file with mode: 0644]
gcc/tree-vect-slp.c

diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-phis-1.c b/gcc/testsuite/gcc.dg/vect/bb-slp-phis-1.c
new file mode 100644 (file)
index 0000000..014c13b
--- /dev/null
@@ -0,0 +1,20 @@
+/* From gcc.c-torture/execute/loop-13.c  */
+/* { dg-do compile } */
+/* { dg-additional-options "-march=cascadelake" { target x86_64-*-* i?86-*-* } } */
+#define TYPE long
+
+void
+scale (TYPE *alpha, TYPE *x, int n)
+{
+  int i, ix;
+
+  if (*alpha != 1)
+    for (i = 0, ix = 0; i < n; i++, ix += 2)
+      {
+       TYPE tmpr, tmpi;
+       tmpr = *alpha * x[ix];
+       tmpi = *alpha * x[ix + 1];
+       x[ix] = tmpr;
+       x[ix + 1] = tmpi;
+      }
+}
index 7e22506b49fac15ed90ab65efbd4b5026c5b8391..dbe76ac72514d58a2ca5671b9221afa3a3f4f11c 100644 (file)
@@ -4144,7 +4144,9 @@ vect_create_constant_vectors (vec_info *vinfo, slp_tree op_node)
                  if (insert_after)
                    {
                      gimple_stmt_iterator gsi;
-                     if (!stmt_ends_bb_p (insert_after->stmt))
+                     if (gimple_code (insert_after->stmt) == GIMPLE_PHI)
+                       gsi = gsi_after_labels (gimple_bb (insert_after->stmt));
+                     else if (!stmt_ends_bb_p (insert_after->stmt))
                        gsi = gsi_for_stmt (insert_after->stmt);
                      else
                        {