tree-optimization/98685 - fix placement of extern converts
authorRichard Biener <rguenther@suse.de>
Fri, 15 Jan 2021 09:08:58 +0000 (10:08 +0100)
committerRichard Biener <rguenther@suse.de>
Fri, 15 Jan 2021 10:26:57 +0000 (11:26 +0100)
Avoid advancing to the next stmt when inserting at region boundary
and deal with a vector def being not the only child.

2021-01-15  Richard Biener  <rguenther@suse.de>

PR tree-optimization/98685
* tree-vect-slp.c (vect_schedule_slp_node): Refactor handling
of vector extern defs.

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

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

diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-pr98685.c b/gcc/testsuite/gcc.dg/vect/bb-slp-pr98685.c
new file mode 100644 (file)
index 0000000..b213335
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-O3" } */
+
+char onelock_lock[16];
+void write(void);
+
+void lockit(int count) {
+  for (; count;) {
+    int pid, i;
+    char *p;
+    for (i = 0, p = (char *)&pid; i < sizeof 0; i++)
+      onelock_lock[i] = *p++;
+    write();
+  }
+}
index 6b6c9ccc0a021b118052a3a8d562ea0cfdc68335..1787ad742682bf285f04104667620e739ab5bffe 100644 (file)
@@ -5915,6 +5915,7 @@ vect_schedule_slp_node (vec_info *vinfo,
       /* Emit other stmts after the children vectorized defs which is
         earliest possible.  */
       gimple *last_stmt = NULL;
+      bool seen_vector_def = false;
       FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child)
        if (SLP_TREE_DEF_TYPE (child) == vect_internal_def)
          {
@@ -5966,8 +5967,7 @@ vect_schedule_slp_node (vec_info *vinfo,
               we do not insert before the region boundary.  */
            if (SLP_TREE_SCALAR_OPS (child).is_empty ()
                && !vinfo->lookup_def (SLP_TREE_VEC_DEFS (child)[0]))
-             last_stmt = gsi_stmt (gsi_after_labels
-                                     (as_a <bb_vec_info> (vinfo)->bbs[0]));
+             seen_vector_def = true;
            else
              {
                unsigned j;
@@ -5987,7 +5987,12 @@ vect_schedule_slp_node (vec_info *vinfo,
         constants.  */
       if (!last_stmt)
        last_stmt = vect_find_first_scalar_stmt_in_slp (node)->stmt;
-      if (is_a <gphi *> (last_stmt))
+      if (!last_stmt)
+       {
+         gcc_assert (seen_vector_def);
+         si = gsi_after_labels (as_a <bb_vec_info> (vinfo)->bbs[0]);
+       }
+      else if (is_a <gphi *> (last_stmt))
        si = gsi_after_labels (gimple_bb (last_stmt));
       else
        {