]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Remove setting of STMT_VINFO_VECTYPE on non-dataref stmts
authorRichard Biener <rguenther@suse.de>
Thu, 10 Jul 2025 09:37:14 +0000 (11:37 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 8 Aug 2025 13:20:58 +0000 (15:20 +0200)
The following removes early setting of STMT_VINFO_VECTYPE and as
side-effect early failing if we fail to compute a vector type.  The
latter is now ensured by SLP build.  The former is still temporarily
copied from the SLP tree during stmt analysis, and data reference
stmts will still have STMT_VINFO_VECTYPE given existing uses in
dependence and alignment analysis and peeling.

* tree-vect-loop.cc (vect_determine_vectype_for_stmt_1): Remove.
(vect_determine_vectype_for_stmt): Likewise.
(vect_set_stmts_vectype): Likewise.
(vect_analyze_loop_2): Do not call vect_set_stmts_vectype.
* tree-vect-stmts.cc (vect_mark_stmts_to_be_vectorized): Detect
irregular stmts early here.

gcc/tree-vect-loop.cc
gcc/tree-vect-stmts.cc

index cab503caf48b35255c3463d90fc76517422b27f8..5fc24dc8fcdbba0a3b083f34142d8b05130d093d 100644 (file)
@@ -163,169 +163,6 @@ static void vect_estimate_min_profitable_iters (loop_vec_info, int *, int *,
 static stmt_vec_info vect_is_simple_reduction (loop_vec_info, stmt_vec_info,
                                               bool *, bool *, bool);
 
-/* Subroutine of vect_determine_vf_for_stmt that handles only one
-   statement.  VECTYPE_MAYBE_SET_P is true if STMT_VINFO_VECTYPE
-   may already be set for general statements (not just data refs).  */
-
-static opt_result
-vect_determine_vectype_for_stmt_1 (vec_info *vinfo, stmt_vec_info stmt_info,
-                                  bool vectype_maybe_set_p)
-{
-  gimple *stmt = stmt_info->stmt;
-
-  if ((!STMT_VINFO_RELEVANT_P (stmt_info)
-       && !STMT_VINFO_LIVE_P (stmt_info))
-      || gimple_clobber_p (stmt))
-    {
-      if (dump_enabled_p ())
-       dump_printf_loc (MSG_NOTE, vect_location, "skip.\n");
-      return opt_result::success ();
-    }
-
-  tree stmt_vectype, nunits_vectype;
-  opt_result res = vect_get_vector_types_for_stmt (vinfo, stmt_info,
-                                                  &stmt_vectype,
-                                                  &nunits_vectype);
-  if (!res)
-    return res;
-
-  if (stmt_vectype)
-    {
-      if (STMT_VINFO_VECTYPE (stmt_info))
-       /* The only case when a vectype had been already set is for stmts
-          that contain a data ref, or for "pattern-stmts" (stmts generated
-          by the vectorizer to represent/replace a certain idiom).  */
-       gcc_assert ((STMT_VINFO_DATA_REF (stmt_info)
-                    || vectype_maybe_set_p)
-                   && STMT_VINFO_VECTYPE (stmt_info) == stmt_vectype);
-      else
-       STMT_VINFO_VECTYPE (stmt_info) = stmt_vectype;
-    }
-
-  return opt_result::success ();
-}
-
-/* Subroutine of vect_determine_vectorization_factor.  Set the vector
-   types of STMT_INFO and all attached pattern statements and update
-   the vectorization factor VF accordingly.  Return true on success
-   or false if something prevented vectorization.  */
-
-static opt_result
-vect_determine_vectype_for_stmt (vec_info *vinfo, stmt_vec_info stmt_info)
-{
-  if (dump_enabled_p ())
-    dump_printf_loc (MSG_NOTE, vect_location, "==> examining statement: %G",
-                    stmt_info->stmt);
-  opt_result res = vect_determine_vectype_for_stmt_1 (vinfo, stmt_info, false);
-  if (!res)
-    return res;
-
-  if (STMT_VINFO_IN_PATTERN_P (stmt_info)
-      && STMT_VINFO_RELATED_STMT (stmt_info))
-    {
-      gimple *pattern_def_seq = STMT_VINFO_PATTERN_DEF_SEQ (stmt_info);
-      stmt_info = STMT_VINFO_RELATED_STMT (stmt_info);
-
-      /* If a pattern statement has def stmts, analyze them too.  */
-      for (gimple_stmt_iterator si = gsi_start (pattern_def_seq);
-          !gsi_end_p (si); gsi_next (&si))
-       {
-         stmt_vec_info def_stmt_info = vinfo->lookup_stmt (gsi_stmt (si));
-         if (dump_enabled_p ())
-           dump_printf_loc (MSG_NOTE, vect_location,
-                            "==> examining pattern def stmt: %G",
-                            def_stmt_info->stmt);
-         res = vect_determine_vectype_for_stmt_1 (vinfo, def_stmt_info, true);
-         if (!res)
-           return res;
-       }
-
-      if (dump_enabled_p ())
-       dump_printf_loc (MSG_NOTE, vect_location,
-                        "==> examining pattern statement: %G",
-                        stmt_info->stmt);
-      res = vect_determine_vectype_for_stmt_1 (vinfo, stmt_info, true);
-      if (!res)
-       return res;
-    }
-
-  return opt_result::success ();
-}
-
-/* Function vect_set_stmts_vectype
-
-   Set STMT_VINFO_VECTYPE of all stmts.  */
-
-static opt_result
-vect_set_stmts_vectype (loop_vec_info loop_vinfo)
-{
-  class loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
-  basic_block *bbs = LOOP_VINFO_BBS (loop_vinfo);
-  unsigned nbbs = loop->num_nodes;
-  tree scalar_type = NULL_TREE;
-  gphi *phi;
-  tree vectype;
-  stmt_vec_info stmt_info;
-  unsigned i;
-
-  DUMP_VECT_SCOPE ("vect_set_stmts_vectype");
-
-  for (i = 0; i < nbbs; i++)
-    {
-      basic_block bb = bbs[i];
-
-      for (gphi_iterator si = gsi_start_phis (bb); !gsi_end_p (si);
-          gsi_next (&si))
-       {
-         phi = si.phi ();
-         stmt_info = loop_vinfo->lookup_stmt (phi);
-         if (dump_enabled_p ())
-           dump_printf_loc (MSG_NOTE, vect_location, "==> examining phi: %G",
-                            (gimple *) phi);
-
-         gcc_assert (stmt_info);
-
-         if (STMT_VINFO_RELEVANT_P (stmt_info)
-             || STMT_VINFO_LIVE_P (stmt_info))
-            {
-             gcc_assert (!STMT_VINFO_VECTYPE (stmt_info));
-              scalar_type = TREE_TYPE (PHI_RESULT (phi));
-
-             if (dump_enabled_p ())
-               dump_printf_loc (MSG_NOTE, vect_location,
-                                "get vectype for scalar type:  %T\n",
-                                scalar_type);
-
-             vectype = get_vectype_for_scalar_type (loop_vinfo, scalar_type);
-             if (!vectype)
-               return opt_result::failure_at (phi,
-                                              "not vectorized: unsupported "
-                                              "data-type %T\n",
-                                              scalar_type);
-             STMT_VINFO_VECTYPE (stmt_info) = vectype;
-
-             if (dump_enabled_p ())
-               dump_printf_loc (MSG_NOTE, vect_location, "vectype: %T\n",
-                                vectype);
-           }
-       }
-
-      for (gimple_stmt_iterator si = gsi_start_bb (bb); !gsi_end_p (si);
-          gsi_next (&si))
-       {
-         if (is_gimple_debug (gsi_stmt (si)))
-           continue;
-         stmt_info = loop_vinfo->lookup_stmt (gsi_stmt (si));
-         opt_result res
-           = vect_determine_vectype_for_stmt (loop_vinfo, stmt_info);
-         if (!res)
-           return res;
-        }
-    }
-
-  return opt_result::success ();
-}
-
 
 /* Function vect_is_simple_iv_evolution.
 
@@ -2483,15 +2320,6 @@ vect_analyze_loop_2 (loop_vec_info loop_vinfo, bool &fatal,
     }
   LOOP_VINFO_MAX_VECT_FACTOR (loop_vinfo) = max_vf;
 
-  ok = vect_set_stmts_vectype (loop_vinfo);
-  if (!ok)
-    {
-      if (dump_enabled_p ())
-       dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
-                        "cannot determine vector types.\n");
-      return ok;
-    }
-
   /* Compute the scalar iteration cost.  */
   vect_compute_single_scalar_iteration_cost (loop_vinfo);
 
index eff5e88930816ebddaf2e515904601b3b8a0819f..26d5be51892279aeb6354ac9cae6f5fc7b1c58da 100644 (file)
@@ -724,14 +724,21 @@ vect_mark_stmts_to_be_vectorized (loop_vec_info loop_vinfo, bool *fatal)
          if (vect_stmt_relevant_p (phi_info, loop_vinfo, &relevant, &live_p))
            vect_mark_relevant (&worklist, phi_info, relevant, live_p);
        }
-      for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
+      for (si = gsi_after_labels (bb); !gsi_end_p (si); gsi_next (&si))
        {
-         if (is_gimple_debug (gsi_stmt (si)))
+         gimple *stmt = gsi_stmt (si);
+         if (is_gimple_debug (stmt))
            continue;
-         stmt_vec_info stmt_info = loop_vinfo->lookup_stmt (gsi_stmt (si));
+         stmt_vec_info stmt_info = loop_vinfo->lookup_stmt (stmt);
          if (dump_enabled_p ())
              dump_printf_loc (MSG_NOTE, vect_location,
-                              "init: stmt relevant? %G", stmt_info->stmt);
+                              "init: stmt relevant? %G", stmt);
+
+         if (gimple_get_lhs (stmt) == NULL_TREE
+             && !is_a <gcond *> (stmt)
+             && !is_a <gcall *> (stmt))
+           return opt_result::failure_at
+               (stmt, "not vectorized: irregular stmt: %G", stmt);
 
          if (vect_stmt_relevant_p (stmt_info, loop_vinfo, &relevant, &live_p))
            vect_mark_relevant (&worklist, stmt_info, relevant, live_p);