Previously, the check_load_store_for_partial_vectors function
had no return value; instead, it assigned false to
LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo). That design is
inflexible and prevents implementation of tail-predication
for basic block SLP vectorization, because BB SLP needs to act
immediately on the fact that the relevant load or store cannot be
vectorized instead of deferring action.

Refactor this function to return true (meaning that partial vectors
are supported) or false.  The function is only called if the current
partial vector state is true, therefore its return value could be
assigned directly as the new state regardless of whether it is true
or false.  Don't actually do that though, with an eye to future
modifications to enable predicated tails for BB SLP vectorization.

gcc/ChangeLog:

        * tree-vect-stmts.cc (check_load_store_for_partial_vectors):
        Return true if partial vectors can be used.
        Return false instead of assigning false to
        LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) if
        partial vectors cannot be used.
        (vectorizable_store): If check_load_store_for_partial_vectors
        returns false then assign false to
        LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo).
        (vectorizable_load): As above.
---
 gcc/tree-vect-stmts.cc | 47 +++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 23 deletions(-)

diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 8bf62074baa..6947bad7a95 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -1457,18 +1457,17 @@ vect_get_load_store_partial_vector_style (tree vectype, 
bool is_load,
    its arguments.  If the load or store is conditional, SCALAR_MASK is the
    condition under which it occurs.
 
-   Clear LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P if a loop using partial
-   vectors is not supported, otherwise record the required rgroup control
-   types.
+   Return false if a loop using partial vectors is not supported, otherwise
+   record the required rgroup control types.
 
    If partial vectors can be used and ELSVALS is nonzero the supported
    else values will be added to the vector ELSVALS points to.  */
 
-static void
+static bool
 check_load_store_for_partial_vectors (loop_vec_info loop_vinfo, tree vectype,
                                      slp_tree slp_node,
                                      vec_load_store_type vls_type,
-                                     int group_size,
+                                     unsigned int group_size,
                                      vect_load_store_data *ls,
                                      slp_tree mask_node,
                                      vec<int> *elsvals = nullptr)
@@ -1477,7 +1476,7 @@ check_load_store_for_partial_vectors (loop_vec_info 
loop_vinfo, tree vectype,
 
   /* Invariant loads need no special support.  */
   if (memory_access_type == VMAT_INVARIANT)
-    return;
+    return true;
 
   /* Figure whether the mask is uniform.  scalar_mask is used to
      populate the scalar_cond_masked_set.  */
@@ -1517,9 +1516,9 @@ check_load_store_for_partial_vectors (loop_vec_info 
loop_vinfo, tree vectype,
                             "can't operate on partial vectors because"
                             " the target doesn't have an appropriate"
                             " load/store-lanes instruction.\n");
-         LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
+         return false;
        }
-      return;
+      return true;
     }
 
   if (mat_gather_scatter_p (memory_access_type))
@@ -1565,9 +1564,9 @@ check_load_store_for_partial_vectors (loop_vec_info 
loop_vinfo, tree vectype,
                             "can't operate on partial vectors because"
                             " the target doesn't have an appropriate"
                             " gather load or scatter store instruction.\n");
-         LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
+         return false;
        }
-      return;
+      return true;
     }
 
   if (memory_access_type != VMAT_CONTIGUOUS)
@@ -1578,8 +1577,7 @@ check_load_store_for_partial_vectors (loop_vec_info 
loop_vinfo, tree vectype,
        dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
                         "can't operate on partial vectors because an"
                         " access isn't contiguous.\n");
-      LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
-      return;
+      return false;
     }
 
   if (!VECTOR_MODE_P (vecmode))
@@ -1588,8 +1586,7 @@ check_load_store_for_partial_vectors (loop_vec_info 
loop_vinfo, tree vectype,
        dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
                         "can't operate on partial vectors when emulating"
                         " vector operations.\n");
-      LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
-      return;
+      return false;
     }
 
   /* We might load more scalars than we need for permuting SLP loads.
@@ -1628,8 +1625,9 @@ check_load_store_for_partial_vectors (loop_vec_info 
loop_vinfo, tree vectype,
                         "can't operate on partial vectors because the"
                         " target doesn't have the appropriate partial"
                         " vectorization load or store.\n");
-      LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
+      return false;
     }
+  return true;
 }
 
 /* Return the mask input to a masked load or store.  VEC_MASK is the vectorized
@@ -8313,10 +8311,11 @@ vectorizable_store (vec_info *vinfo,
   if (costing_p) /* transformation not required.  */
     {
       if (loop_vinfo
-         && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
-       check_load_store_for_partial_vectors (loop_vinfo, vectype, slp_node,
-                                             vls_type, group_size, &ls,
-                                             mask_node);
+         && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
+         && !check_load_store_for_partial_vectors (loop_vinfo, vectype,
+                                                   slp_node, vls_type,
+                                                   group_size, &ls, mask_node))
+       LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
 
       if (!vect_maybe_update_slp_op_vectype (op_node, vectype)
          || (mask_node
@@ -9958,10 +9957,12 @@ vectorizable_load (vec_info *vinfo,
   if (costing_p) /* transformation not required.  */
     {
       if (loop_vinfo
-         && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
-       check_load_store_for_partial_vectors (loop_vinfo, vectype, slp_node,
-                                             VLS_LOAD, group_size, &ls,
-                                             mask_node, &ls.elsvals);
+         && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
+         && !check_load_store_for_partial_vectors (loop_vinfo, vectype,
+                                                   slp_node, VLS_LOAD,
+                                                   group_size, &ls, mask_node,
+                                                   &ls.elsvals))
+       LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
 
       /* If the type needs padding we must zero inactive elements.
         Check if we can do that with a VEC_COND_EXPR and store the
-- 
2.43.0

Reply via email to