c++: Improve access checking inside templates [PR41437]
[gcc.git] / gcc / tree-vect-stmts.c
index 686eb389f0c98b717712a4c25435ca9f8b05877d..cf2d979fea11e1a4cb47f31e5b591a5f0a91a852 100644 (file)
@@ -636,6 +636,8 @@ vect_mark_stmts_to_be_vectorized (loop_vec_info loop_vinfo, bool *fatal)
        }
       for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
        {
+         if (is_gimple_debug (gsi_stmt (si)))
+           continue;
          stmt_vec_info stmt_info = loop_vinfo->lookup_stmt (gsi_stmt (si));
          if (dump_enabled_p ())
              dump_printf_loc (MSG_NOTE, vect_location,
@@ -1653,9 +1655,9 @@ static tree permute_vec_elements (vec_info *, tree, tree, tree, stmt_vec_info,
                                  gimple_stmt_iterator *);
 
 /* Check whether a load or store statement in the loop described by
-   LOOP_VINFO is possible in a fully-masked loop.  This is testing
-   whether the vectorizer pass has the appropriate support, as well as
-   whether the target does.
+   LOOP_VINFO is possible in a loop using partial vectors.  This is
+   testing whether the vectorizer pass has the appropriate support,
+   as well as whether the target does.
 
    VLS_TYPE says whether the statement is a load or store and VECTYPE
    is the type of the vector being loaded or stored.  MEMORY_ACCESS_TYPE
@@ -1665,14 +1667,18 @@ static tree permute_vec_elements (vec_info *, tree, tree, tree, stmt_vec_info,
    its arguments.  If the load or store is conditional, SCALAR_MASK is the
    condition under which it occurs.
 
-   Clear LOOP_VINFO_CAN_FULLY_MASK_P if a fully-masked loop is not
-   supported, otherwise record the required mask types.  */
+   Clear LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P if a loop using partial
+   vectors is not supported, otherwise record the required rgroup control
+   types.  */
 
 static void
-check_load_store_masking (loop_vec_info loop_vinfo, tree vectype,
-                         vec_load_store_type vls_type, int group_size,
-                         vect_memory_access_type memory_access_type,
-                         gather_scatter_info *gs_info, tree scalar_mask)
+check_load_store_for_partial_vectors (loop_vec_info loop_vinfo, tree vectype,
+                                     vec_load_store_type vls_type,
+                                     int group_size,
+                                     vect_memory_access_type
+                                     memory_access_type,
+                                     gather_scatter_info *gs_info,
+                                     tree scalar_mask)
 {
   /* Invariant loads need no special support.  */
   if (memory_access_type == VMAT_INVARIANT)
@@ -1689,10 +1695,10 @@ check_load_store_masking (loop_vec_info loop_vinfo, tree vectype,
        {
          if (dump_enabled_p ())
            dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
-                            "can't use a fully-masked loop because the"
-                            " target doesn't have an appropriate masked"
+                            "can't operate on partial vectors because"
+                            " the target doesn't have an appropriate"
                             " load/store-lanes instruction.\n");
-         LOOP_VINFO_CAN_FULLY_MASK_P (loop_vinfo) = false;
+         LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
          return;
        }
       unsigned int ncopies = vect_get_num_copies (loop_vinfo, vectype);
@@ -1712,10 +1718,10 @@ check_load_store_masking (loop_vec_info loop_vinfo, tree vectype,
        {
          if (dump_enabled_p ())
            dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
-                            "can't use a fully-masked loop because the"
-                            " target doesn't have an appropriate masked"
+                            "can't operate on partial vectors because"
+                            " the target doesn't have an appropriate"
                             " gather load or scatter store instruction.\n");
-         LOOP_VINFO_CAN_FULLY_MASK_P (loop_vinfo) = false;
+         LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
          return;
        }
       unsigned int ncopies = vect_get_num_copies (loop_vinfo, vectype);
@@ -1730,9 +1736,9 @@ check_load_store_masking (loop_vec_info loop_vinfo, tree vectype,
         scalar loop.  We need more work to support other mappings.  */
       if (dump_enabled_p ())
        dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
-                        "can't use a fully-masked loop because an access"
-                        " isn't contiguous.\n");
-      LOOP_VINFO_CAN_FULLY_MASK_P (loop_vinfo) = false;
+                        "can't operate on partial vectors because an"
+                        " access isn't contiguous.\n");
+      LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
       return;
     }
 
@@ -1746,7 +1752,7 @@ check_load_store_masking (loop_vec_info loop_vinfo, tree vectype,
                         "can't use a fully-masked loop because the target"
                         " doesn't have the appropriate masked load or"
                         " store.\n");
-      LOOP_VINFO_CAN_FULLY_MASK_P (loop_vinfo) = false;
+      LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
       return;
     }
   /* We might load more scalars than we need for permuting SLP loads.
@@ -5864,7 +5870,7 @@ vectorizable_operation (vec_info *vinfo,
         should only change the active lanes of the reduction chain,
         keeping the inactive lanes as-is.  */
       if (loop_vinfo
-         && LOOP_VINFO_CAN_FULLY_MASK_P (loop_vinfo)
+         && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
          && reduc_idx >= 0)
        {
          if (cond_fn == IFN_LAST
@@ -5875,7 +5881,7 @@ vectorizable_operation (vec_info *vinfo,
                dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
                                 "can't use a fully-masked loop because no"
                                 " conditional operation is available.\n");
-             LOOP_VINFO_CAN_FULLY_MASK_P (loop_vinfo) = false;
+             LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
            }
          else
            vect_record_loop_mask (loop_vinfo, masks, ncopies * vec_num,
@@ -7137,9 +7143,10 @@ vectorizable_store (vec_info *vinfo,
       STMT_VINFO_MEMORY_ACCESS_TYPE (stmt_info) = memory_access_type;
 
       if (loop_vinfo
-         && LOOP_VINFO_CAN_FULLY_MASK_P (loop_vinfo))
-       check_load_store_masking (loop_vinfo, vectype, vls_type, group_size,
-                                 memory_access_type, &gs_info, mask);
+         && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
+       check_load_store_for_partial_vectors (loop_vinfo, vectype, vls_type,
+                                             group_size, memory_access_type,
+                                             &gs_info, mask);
 
       if (slp_node
          && !vect_maybe_update_slp_op_vectype (SLP_TREE_CHILDREN (slp_node)[0],
@@ -8430,9 +8437,10 @@ vectorizable_load (vec_info *vinfo,
        STMT_VINFO_MEMORY_ACCESS_TYPE (stmt_info) = memory_access_type;
 
       if (loop_vinfo
-         && LOOP_VINFO_CAN_FULLY_MASK_P (loop_vinfo))
-       check_load_store_masking (loop_vinfo, vectype, VLS_LOAD, group_size,
-                                 memory_access_type, &gs_info, mask);
+         && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
+       check_load_store_for_partial_vectors (loop_vinfo, vectype, VLS_LOAD,
+                                             group_size, memory_access_type,
+                                             &gs_info, mask);
 
       STMT_VINFO_TYPE (orig_stmt_info) = load_vec_info_type;
       vect_model_load_cost (vinfo, stmt_info, ncopies, vf, memory_access_type,
@@ -9843,7 +9851,7 @@ vectorizable_condition (vec_info *vinfo,
        }
 
       if (loop_vinfo
-         && LOOP_VINFO_CAN_FULLY_MASK_P (loop_vinfo)
+         && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
          && reduction_type == EXTRACT_LAST_REDUCTION)
        vect_record_loop_mask (loop_vinfo, &LOOP_VINFO_MASKS (loop_vinfo),
                               ncopies * vec_num, vectype, NULL);
@@ -9917,7 +9925,8 @@ vectorizable_condition (vec_info *vinfo,
   FOR_EACH_VEC_ELT (vec_oprnds0, i, vec_cond_lhs)
     {
       vec_then_clause = vec_oprnds2[i];
-      vec_else_clause = vec_oprnds3[i];
+      if (reduction_type != EXTRACT_LAST_REDUCTION)
+       vec_else_clause = vec_oprnds3[i];
 
       if (swap_cond_operands)
        std::swap (vec_then_clause, vec_else_clause);