random vectorizer fixes
authorRichard Biener <rguenther@suse.de>
Thu, 10 Sep 2020 14:23:29 +0000 (16:23 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 11 Sep 2020 06:10:38 +0000 (08:10 +0200)
This fixes random things found when doing SLP discovery from
arbitrary sets of stmts.

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

* tree-vect-slp.c (vect_build_slp_tree_1): Check vector
types for all lanes are compatible.
(vect_analyze_slp_instance): Appropriately check for stores.
(vect_schedule_slp): Likewise.

gcc/tree-vect-slp.c

index 458a2c5bb301157f4f843776943435eba8c49d65..aa6aa3328e81158e8c62bbca76033dd7982cde8d 100644 (file)
@@ -1007,6 +1007,16 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap,
                  continue;
                }
            }
+
+         if (!types_compatible_p (vectype, *node_vectype))
+           {
+             if (dump_enabled_p ())
+               dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+                                "Build SLP failed: different vector type "
+                                "in %G", stmt);
+             /* Mismatch.  */
+             continue;
+           }
        }
 
       /* Grouped store or load.  */
@@ -2382,7 +2392,7 @@ vect_analyze_slp_instance (vec_info *vinfo,
   unsigned HOST_WIDE_INT const_nunits;
   if (is_a <bb_vec_info> (vinfo)
       && STMT_VINFO_GROUPED_ACCESS (stmt_info)
-      && DR_GROUP_FIRST_ELEMENT (stmt_info)
+      && DR_IS_WRITE (STMT_VINFO_DATA_REF (stmt_info))
       && nunits.is_constant (&const_nunits))
     {
       /* We consider breaking the group only on VF boundaries from the existing
@@ -4893,14 +4903,13 @@ vect_schedule_slp (vec_info *vinfo)
       if (is_a <loop_vec_info> (vinfo))
        vect_remove_slp_scalar_calls (vinfo, root);
 
+      /* Remove vectorized stores original scalar stmts.  */
       for (j = 0; SLP_TREE_SCALAR_STMTS (root).iterate (j, &store_info); j++)
         {
-         if (!STMT_VINFO_DATA_REF (store_info))
+         if (!STMT_VINFO_DATA_REF (store_info)
+             || !DR_IS_WRITE (STMT_VINFO_DATA_REF (store_info)))
            break;
 
-         if (SLP_INSTANCE_ROOT_STMT (instance))
-           continue;
-
          store_info = vect_orig_stmt (store_info);
          /* Free the attached stmt_vec_info and remove the stmt.  */
          vinfo->remove_stmt (store_info);