On Fri, 5 Feb 2021, Richard Biener wrote:
> On Fri, 5 Feb 2021, Richard Sandiford wrote:
>
> > Richard Biener <[email protected]> writes:
> > > On Fri, 5 Feb 2021, Richard Sandiford wrote:
> > >> Richard Biener <[email protected]> writes:
> > >> > + /* First produce cost vectors sorted by loop index. */
> > >> > + auto_vec<std::pair<unsigned, stmt_info_for_cost *> >
> > >> > + li_scalar_costs (scalar_costs.length ());
> > >> > + auto_vec<std::pair<unsigned, stmt_info_for_cost *> >
> > >> > + li_vector_costs (vector_costs.length ());
> > >> > + FOR_EACH_VEC_ELT (scalar_costs, i, cost)
> > >> > + {
> > >> > + unsigned l = gimple_bb
> > >> > (cost->stmt_info->stmt)->loop_father->num;
> > >> > + li_scalar_costs.quick_push (std::make_pair (l, cost));
> > >> > + }
> > >> > + unsigned l = li_scalar_costs[0].first;
> > >>
> > >> Is this just to silence an unused warning? Might be worth a comment if
> > >> so
> > >> (although couldn't we just use 0?).
> > >
> > > The issue is that not all vector_costs entries have a stmt_info so
> > > this uses a random loop also used in the scalar code (that's going
> > > to be the correct loop in case there's only one loop involved which
> > > is probably 99% of the cases). I'mm add a comment.
> >
> > Hmm, OK, but I thought the comment below was saying that all such
> > cases follow the relevant statement, instead of coming first.
> > Is this situation specific to the first run of costs?
>
> It's to some extent out of caution since I did not try to provoke
> the situation but I think there are some paths in costing that
> fail to set a stmt_info for costing of an acutal stmt. While
> we do want to fix this I don't think it's appropriate to ICE
> for the cases at this point.
So the following passes vect.exp testing on x86_64 but I'm quite
sure it will eventually trigger.
Richard.
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index b9f12c30fb8..0737621cb1b 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -4412,13 +4412,14 @@ vect_bb_vectorization_profitable_p (bb_vec_info
bb_vinfo,
}
/* Use a random used loop as fallback in case the first vector_costs
entry does not have a stmt_info associated with it. */
- unsigned l = li_scalar_costs[0].first;
+ unsigned l = -1u;
FOR_EACH_VEC_ELT (vector_costs, i, cost)
{
/* We inherit from the previous COST, invariants, externals and
extracts immediately follow the cost for the related stmt. */
if (cost->stmt_info)
l = gimple_bb (cost->stmt_info->stmt)->loop_father->num;
+ gcc_assert (l != -1u);
li_vector_costs.quick_push (std::make_pair (l, cost));
}
li_scalar_costs.qsort (li_cost_vec_cmp);