diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
index cd1ea746ae4..6264e977bec 100644
--- a/gcc/tree-vect-loop-manip.cc
+++ b/gcc/tree-vect-loop-manip.cc
@@ -514,7 +514,6 @@ vect_set_loop_controls_directly (class loop *loop,
loop_vec_info loop_vinfo,
tree ctrl_type = rgc->type;
unsigned int nitems_per_iter = rgc->max_nscalars_per_iter * rgc->factor;
poly_uint64 nitems_per_ctrl = TYPE_VECTOR_SUBPARTS (ctrl_type) * rgc-
factor;
- poly_uint64 vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo);
tree length_limit = NULL_TREE;
/* For length, we need length_limit to ensure length in range. */
if (!use_masks_p)
@@ -525,7 +524,11 @@ vect_set_loop_controls_directly (class loop *loop,
loop_vec_info loop_vinfo,
of the vector loop, and the number that it should skip during the
first iteration of the vector loop. */
tree nitems_total = niters;
- tree nitems_step = build_int_cst (iv_type, vf);
+ tree nitems_vf
+ = build_int_cst (iv_type, LOOP_VINFO_VECT_FACTOR (loop_vinfo));
+ tree nitems_step
+ = gimple_convert (&loop_cond_gsi, true, GSI_SAME_STMT,
UNKNOWN_LOCATION,
+ iv_type, LOOP_VINFO_IV_INCREMENT (loop_vinfo));
tree nitems_skip = niters_skip;
if (nitems_per_iter != 1)
{
@@ -535,8 +538,11 @@ vect_set_loop_controls_directly (class loop *loop,
loop_vec_info loop_vinfo,
tree iv_factor = build_int_cst (iv_type, nitems_per_iter);
nitems_total = gimple_build (preheader_seq, MULT_EXPR, compare_type,
nitems_total, compare_factor);
- nitems_step = gimple_build (preheader_seq, MULT_EXPR, iv_type,
- nitems_step, iv_factor);
+ nitems_vf = gimple_build (preheader_seq, MULT_EXPR, iv_type,
+ nitems_vf, iv_factor);
+ nitems_step
+ = gimple_build (&loop_cond_gsi, true, GSI_SAME_STMT,
UNKNOWN_LOCATION,
+ MULT_EXPR, iv_type, nitems_step, iv_factor);
if (nitems_skip)
nitems_skip = gimple_build (preheader_seq, MULT_EXPR,
compare_type,
nitems_skip, compare_factor);
@@ -578,22 +584,27 @@ vect_set_loop_controls_directly (class loop *loop,
loop_vec_info loop_vinfo,
insert_after, &index_before_incr, &index_after_incr);
tree vectype = build_zero_cst (rgc->type);
tree len = gimple_build (header_seq, IFN_SELECT_VL, iv_type,
- index_before_incr, nitems_step,
+ index_before_incr, nitems_vf,
vectype);
gimple_seq_add_stmt (header_seq, gimple_build_assign (step, len));
+ /* Also set the LOOP_VINFO_IV_INCREMENT. */
+ gassign* assign_iv_increment
+ = gimple_build_assign (LOOP_VINFO_IV_INCREMENT (loop_vinfo),
len);
+ gimple_seq_add_stmt (header_seq, assign_iv_increment);