--- /dev/null
+/* { dg-do compile } */
+
+double foo (double x, int n)
+{
+ double s = 0.;
+ for (int i = 0; i < n; ++i)
+ {
+ s += x;
+ s += x;
+ s += x;
+ }
+ return s;
+}
if (STMT_VINFO_DEF_TYPE (stmt_info) == vect_induction_def
&& ! PURE_SLP_STMT (stmt_info))
ok = vectorizable_induction (loop_vinfo,
- stmt_info, NULL, NULL, NULL,
+ stmt_info, NULL, NULL,
&cost_vec);
else if ((STMT_VINFO_DEF_TYPE (stmt_info) == vect_reduction_def
|| (STMT_VINFO_DEF_TYPE (stmt_info)
bool
vectorizable_induction (loop_vec_info loop_vinfo,
stmt_vec_info stmt_info,
- gimple_stmt_iterator *gsi ATTRIBUTE_UNUSED,
gimple **vec_stmt, slp_tree slp_node,
stmt_vector_for_cost *cost_vec)
{
si = gsi_for_stmt (last_stmt_info->stmt);
}
else if (SLP_TREE_CHILDREN (node).is_empty ())
- /* This happens for reduction PHIs. */
- si = gsi_for_stmt (vect_find_last_scalar_stmt_in_slp (node)->stmt);
+ {
+ /* This happens for reduction and induction PHIs where we do not use the
+ insertion iterator. */
+ gcc_assert (STMT_VINFO_TYPE (SLP_TREE_REPRESENTATIVE (node))
+ == cycle_phi_info_type
+ || (STMT_VINFO_TYPE (SLP_TREE_REPRESENTATIVE (node))
+ == induc_vec_info_type));
+ si = gsi_none ();
+ }
else
{
/* Emit other stmts after the children vectorized defs which is
FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child)
if (SLP_TREE_DEF_TYPE (child) == vect_internal_def)
{
+ /* For fold-left reductions we are retaining the scalar
+ reduction PHI but we still have SLP_TREE_NUM_VEC_STMTS
+ set so the representation isn't perfect. Resort to the
+ last scalar def here. */
+ if (SLP_TREE_VEC_STMTS (child).is_empty ())
+ {
+ gcc_assert (STMT_VINFO_TYPE (SLP_TREE_REPRESENTATIVE (child))
+ == cycle_phi_info_type);
+ gphi *phi = as_a <gphi *>
+ (vect_find_last_scalar_stmt_in_slp (child)->stmt);
+ if (!last_stmt
+ || vect_stmt_dominates_stmt_p (last_stmt, phi))
+ last_stmt = phi;
+ }
/* We are emitting all vectorized stmts in the same place and
the last one is the last.
??? Unless we have a load permutation applied and that
|| vectorizable_reduction (as_a <loop_vec_info> (vinfo), stmt_info,
node, node_instance, cost_vec)
|| vectorizable_induction (as_a <loop_vec_info> (vinfo), stmt_info,
- NULL, NULL, node, cost_vec)
+ NULL, node, cost_vec)
|| vectorizable_shift (vinfo, stmt_info, NULL, NULL, node, cost_vec)
|| vectorizable_condition (vinfo, stmt_info,
NULL, NULL, node, cost_vec)
case induc_vec_info_type:
done = vectorizable_induction (as_a <loop_vec_info> (vinfo),
- stmt_info, gsi, &vec_stmt, slp_node,
+ stmt_info, &vec_stmt, slp_node,
NULL);
gcc_assert (done);
break;
slp_tree, slp_instance,
stmt_vector_for_cost *);
extern bool vectorizable_induction (loop_vec_info, stmt_vec_info,
- gimple_stmt_iterator *,
gimple **, slp_tree,
stmt_vector_for_cost *);
extern bool vect_transform_reduction (loop_vec_info, stmt_vec_info,