diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc index 959e127c385..39fd887a96b 100644 --- a/gcc/tree-vect-data-refs.cc +++ b/gcc/tree-vect-data-refs.cc @@ -1041,6 +1041,8 @@ vect_slp_analyze_load_dependences (vec_info *vinfo, slp_tree node, for (unsigned k = 0; k < SLP_TREE_SCALAR_STMTS (node).length (); ++k) { + if (! SLP_TREE_SCALAR_STMTS (node)[k]) + continue; stmt_vec_info access_info = vect_orig_stmt (SLP_TREE_SCALAR_STMTS (node)[k]); if (access_info == first_access_info) diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index 48e0f9d2705..22ed59a817d 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -355,7 +355,7 @@ vect_contains_pattern_stmt_p (vec stmts) stmt_vec_info stmt_info; unsigned int i; FOR_EACH_VEC_ELT (stmts, i, stmt_info) - if (is_pattern_stmt_p (stmt_info)) + if (stmt_info && is_pattern_stmt_p (stmt_info)) return true; return false; } @@ -1591,7 +1591,7 @@ bst_traits::hash (value_type x) { inchash::hash h; for (unsigned i = 0; i < x.length (); ++i) - h.add_int (gimple_uid (x[i]->stmt)); + h.add_int (x[i] ? gimple_uid (x[i]->stmt) : -1); return h.end (); } inline bool @@ -2800,9 +2800,12 @@ vect_print_slp_tree (dump_flags_t dump_kind, dump_location_t loc, } if (SLP_TREE_SCALAR_STMTS (node).exists ()) FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info) - dump_printf_loc (metadata, user_loc, "\t%sstmt %u %G", - STMT_VINFO_LIVE_P (stmt_info) ? "[l] " : "", - i, stmt_info->stmt); + if (stmt_info) + dump_printf_loc (metadata, user_loc, "\t%sstmt %u %G", + STMT_VINFO_LIVE_P (stmt_info) ? "[l] " : "", + i, stmt_info->stmt); + else + dump_printf_loc (metadata, user_loc, "\tstmt %u ---\n", i); else { dump_printf_loc (metadata, user_loc, "\t{ "); @@ -2943,7 +2946,8 @@ vect_mark_slp_stmts (slp_tree node, hash_set &visited) return; FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info) - STMT_SLP_TYPE (stmt_info) = pure_slp; + if (stmt_info) + STMT_SLP_TYPE (stmt_info) = pure_slp; FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child) if (child) @@ -2973,11 +2977,12 @@ vect_mark_slp_stmts_relevant (slp_tree node, hash_set &visited) return; FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info) - { - gcc_assert (!STMT_VINFO_RELEVANT (stmt_info) - || STMT_VINFO_RELEVANT (stmt_info) == vect_used_in_scope); - STMT_VINFO_RELEVANT (stmt_info) = vect_used_in_scope; - } + if (stmt_info) + { + gcc_assert (!STMT_VINFO_RELEVANT (stmt_info) + || STMT_VINFO_RELEVANT (stmt_info) == vect_used_in_scope); + STMT_VINFO_RELEVANT (stmt_info) = vect_used_in_scope; + } FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child) if (child) @@ -3028,10 +3033,11 @@ vect_find_last_scalar_stmt_in_slp (slp_tree node) stmt_vec_info stmt_vinfo; for (int i = 0; SLP_TREE_SCALAR_STMTS (node).iterate (i, &stmt_vinfo); i++) - { - stmt_vinfo = vect_orig_stmt (stmt_vinfo); - last = last ? get_later_stmt (stmt_vinfo, last) : stmt_vinfo; - } + if (stmt_vinfo) + { + stmt_vinfo = vect_orig_stmt (stmt_vinfo); + last = last ? get_later_stmt (stmt_vinfo, last) : stmt_vinfo; + } return last; } @@ -3045,12 +3051,13 @@ vect_find_first_scalar_stmt_in_slp (slp_tree node) stmt_vec_info stmt_vinfo; for (int i = 0; SLP_TREE_SCALAR_STMTS (node).iterate (i, &stmt_vinfo); i++) - { - stmt_vinfo = vect_orig_stmt (stmt_vinfo); - if (!first - || get_later_stmt (stmt_vinfo, first) == first) - first = stmt_vinfo; - } + if (stmt_vinfo) + { + stmt_vinfo = vect_orig_stmt (stmt_vinfo); + if (!first + || get_later_stmt (stmt_vinfo, first) == first) + first = stmt_vinfo; + } return first; } @@ -5908,6 +5915,7 @@ vect_optimize_slp_pass::remove_redundant_permutations () { if (j != 0 && (next_load_info != load_info + || ! load_info || DR_GROUP_GAP (load_info) != 1)) { subchain_p = false; @@ -6524,7 +6532,8 @@ vect_slp_analyze_node_operations_1 (vec_info *vinfo, slp_tree node, unsigned int i; FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, slp_stmt_info) { - if (STMT_VINFO_LIVE_P (slp_stmt_info) + if (slp_stmt_info + && STMT_VINFO_LIVE_P (slp_stmt_info) && !vectorizable_live_operation (vinfo, slp_stmt_info, node, node_instance, i, false, cost_vec)) @@ -6556,6 +6565,10 @@ vect_slp_convert_to_external (vec_info *vinfo, slp_tree node, || VECTOR_BOOLEAN_TYPE_P (SLP_TREE_VECTYPE (node))) return false; + FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info) + if (!stmt_info) + return false; + if (dump_enabled_p ()) dump_printf_loc (MSG_NOTE, vect_location, "Building vector operands of %p from scalars instead\n", @@ -6914,7 +6927,7 @@ vect_bb_slp_mark_live_stmts (bb_vec_info bb_vinfo, slp_tree node, stmt_vec_info last_stmt = vect_find_last_scalar_stmt_in_slp (node); FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info) { - if (svisited.contains (stmt_info)) + if (!stmt_info || svisited.contains (stmt_info)) continue; stmt_vec_info orig_stmt_info = vect_orig_stmt (stmt_info); if (STMT_VINFO_IN_PATTERN_P (orig_stmt_info) @@ -7103,7 +7116,8 @@ vect_slp_prune_covered_roots (slp_tree node, hash_set &roots, stmt_vec_info stmt; unsigned i; FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt) - roots.remove (vect_orig_stmt (stmt)); + if (stmt) + roots.remove (vect_orig_stmt (stmt)); slp_tree child; FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child) @@ -7279,8 +7293,9 @@ vect_bb_partition_graph_r (bb_vec_info bb_vinfo, unsigned i; FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info) - vect_map_to_instance (instance, stmt_info, stmt_to_instance, - instance_leader); + if (stmt_info) + vect_map_to_instance (instance, stmt_info, stmt_to_instance, + instance_leader); if (vect_map_to_instance (instance, node, node_to_instance, instance_leader)) @@ -7348,7 +7363,8 @@ vect_slp_gather_vectorized_scalar_stmts (vec_info *vinfo, slp_tree node, if (SLP_TREE_DEF_TYPE (node) == vect_internal_def) { FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info) - vstmts.add (stmt_info); + if (stmt_info) + vstmts.add (stmt_info); FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child) if (child) @@ -7388,7 +7404,7 @@ vect_bb_slp_scalar_cost (vec_info *vinfo, ssa_op_iter op_iter; def_operand_p def_p; - if ((*life)[i]) + if (!stmt_info || (*life)[i]) continue; stmt_vec_info orig_stmt_info = vect_orig_stmt (stmt_info); @@ -9799,7 +9815,7 @@ vect_schedule_slp_node (vec_info *vinfo, stmt_vec_info slp_stmt_info; unsigned int i; FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, slp_stmt_info) - if (STMT_VINFO_LIVE_P (slp_stmt_info)) + if (slp_stmt_info && STMT_VINFO_LIVE_P (slp_stmt_info)) { done = vectorizable_live_operation (vinfo, slp_stmt_info, node, instance, i, true, NULL); @@ -9843,6 +9859,8 @@ vect_remove_slp_scalar_calls (vec_info *vinfo, FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info) { + if (!stmt_info) + continue; gcall *stmt = dyn_cast (stmt_info->stmt); if (!stmt || gimple_bb (stmt) == NULL) continue; diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index 20b84515446..156c11fee82 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -6191,11 +6191,12 @@ vectorizable_shift (vec_info *vinfo, stmt_vec_info slpstmt_info; FOR_EACH_VEC_ELT (stmts, k, slpstmt_info) - { - gassign *slpstmt = as_a (slpstmt_info->stmt); - if (!operand_equal_p (gimple_assign_rhs2 (slpstmt), op1, 0)) - scalar_shift_arg = false; - } + if (slpstmt_info) + { + gassign *slpstmt = as_a (slpstmt_info->stmt); + if (!operand_equal_p (gimple_assign_rhs2 (slpstmt), op1, 0)) + scalar_shift_arg = false; + } /* For internal SLP defs we have to make sure we see scalar stmts for all vector elements. @@ -13082,11 +13083,12 @@ can_vectorize_live_stmts (vec_info *vinfo, stmt_vec_info stmt_info, unsigned int i; FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (slp_node), i, slp_stmt_info) { - if ((STMT_VINFO_LIVE_P (slp_stmt_info) - || (loop_vinfo - && LOOP_VINFO_EARLY_BREAKS (loop_vinfo) - && STMT_VINFO_DEF_TYPE (slp_stmt_info) - == vect_induction_def)) + if (slp_stmt_info + && (STMT_VINFO_LIVE_P (slp_stmt_info) + || (loop_vinfo + && LOOP_VINFO_EARLY_BREAKS (loop_vinfo) + && STMT_VINFO_DEF_TYPE (slp_stmt_info) + == vect_induction_def)) && !vectorizable_live_operation (vinfo, slp_stmt_info, slp_node, slp_node_instance, i, vec_stmt_p, cost_vec))