> -----Original Message-----
> From: Alfie Richards <[email protected]>
> Sent: 17 September 2026 15:40
> To: [email protected]
> Cc: Alex Coplan <[email protected]>; Alice Carlotti
> <[email protected]>; Andrea Pinski
> <[email protected]>; Richard Biener <[email protected]>;
> Tamar Christina <[email protected]>; Zdenek Dvorak <[email protected]>;
> Robin Dapp <[email protected]>; Richard Sandiford
> <[email protected]>; Kyrylo Tkachov <[email protected]>;
> Alfie Richards <[email protected]>
> Subject: [PATCH v3 02/16] vect: Change IV increment position to
> standard_iv_increment_position
>
> Change both vect_set_loop_controls_directly and
> vect_update_ivs_after_vectorizer_for_early_breaks to use
> standard_iv_increment_position.
>
> This moves the IV increment to the end of the loop which is required for
> situations where the IV increment is loop variant and calculated in the
> loop body, such as HSSR.
>
> gcc/ChangeLog:
>
> * tree-vect-loop-manip.cc (vect_set_loop_controls_directly):
> Use standard_iv_increment_position instead of
> vect_iv_increment_position .
> * tree-vect-loop.cc
> (vect_update_ivs_after_vectorizer_for_early_breaks):
> Likewise.
Patch is OK, but any reason not to change
vect_set_loop_condition_partial_vectors_avx512
and vect_set_loop_condition_normal so all loop controls are materialized in the
same place
consistently?
Thanks,
Tamar
> ---
> gcc/tree-vect-loop-manip.cc | 13 +++++--------
> gcc/tree-vect-loop.cc | 3 +--
> 2 files changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
> index b54353399d9..78445e1f9aa 100644
> --- a/gcc/tree-vect-loop-manip.cc
> +++ b/gcc/tree-vect-loop-manip.cc
> @@ -599,8 +599,8 @@ vect_set_loop_controls_directly (class loop *loop,
> loop_vec_info loop_vinfo,
> tree index_before_incr, index_after_incr;
> gimple_stmt_iterator incr_gsi;
> bool insert_after;
> - edge exit_e = LOOP_VINFO_MAIN_EXIT (loop_vinfo);
> - vect_iv_increment_position (exit_e, &incr_gsi, &insert_after);
> + standard_iv_increment_position (loop, &incr_gsi, &insert_after);
> +
> if (LOOP_VINFO_USING_DECREMENTING_IV_P (loop_vinfo))
> {
> /* Create an IV that counts down from niters_total and whose step
> @@ -670,7 +670,6 @@ vect_set_loop_controls_directly (class loop *loop,
> loop_vec_info loop_vinfo,
>
> tree zero_index = build_int_cst (compare_type, 0);
> tree test_index, test_limit, first_limit;
> - gimple_stmt_iterator *test_gsi;
> if (might_wrap_p)
> {
> /* In principle the loop should stop iterating once the incremented
> @@ -709,7 +708,6 @@ vect_set_loop_controls_directly (class loop *loop,
> loop_vec_info loop_vinfo,
> nitems_total, adjust);
> test_limit = gimple_build (preheader_seq, MINUS_EXPR, compare_type,
> test_limit, adjust);
> - test_gsi = &incr_gsi;
>
> /* Get a safe limit for the first iteration. */
> if (nitems_skip)
> @@ -740,7 +738,6 @@ vect_set_loop_controls_directly (class loop *loop,
> loop_vec_info loop_vinfo,
> if (nitems_skip)
> test_limit = gimple_build (preheader_seq, PLUS_EXPR, compare_type,
> test_limit, nitems_skip);
> - test_gsi = &loop_cond_gsi;
>
> first_limit = test_limit;
> }
> @@ -749,7 +746,7 @@ vect_set_loop_controls_directly (class loop *loop,
> loop_vec_info loop_vinfo,
> a demotion). */
> gimple_seq test_seq = NULL;
> test_index = gimple_convert (&test_seq, compare_type, test_index);
> - gsi_insert_seq_before (test_gsi, test_seq, GSI_SAME_STMT);
> + gsi_insert_seq_after (&incr_gsi, test_seq, GSI_NEW_STMT);
>
> /* Provide a definition of each control in the group. */
> tree next_ctrl = NULL_TREE;
> @@ -858,14 +855,14 @@ vect_set_loop_controls_directly (class loop *loop,
> loop_vec_info loop_vinfo,
> gimple_seq stmts = NULL;
> next_ctrl = vect_gen_while (&stmts, ctrl_type, test_index,
> this_test_limit, "next_mask");
> - gsi_insert_seq_before (test_gsi, stmts, GSI_SAME_STMT);
> + gsi_insert_seq_after (&incr_gsi, stmts, GSI_SAME_STMT);
> }
> else
> {
> next_ctrl = make_temp_ssa_name (compare_type, NULL,
> "next_len");
> gimple_seq seq = vect_gen_len (next_ctrl, test_index, this_test_limit,
> length_limit);
> - gsi_insert_seq_before (test_gsi, seq, GSI_SAME_STMT);
> + gsi_insert_seq_after (&incr_gsi, seq, GSI_SAME_STMT);
> }
>
> vect_set_loop_control (loop, ctrl, init_ctrl, next_ctrl);
> diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
> index c7407098dc1..fdd224b50f9 100644
> --- a/gcc/tree-vect-loop.cc
> +++ b/gcc/tree-vect-loop.cc
> @@ -11186,8 +11186,7 @@
> vect_update_ivs_after_vectorizer_for_early_breaks (loop_vec_info loop_vinfo)
> /* Write the adjustments at the end of the iv increment. */
> bool insert_after;
> gimple_stmt_iterator incr_gsi;
> - vect_iv_increment_position (LOOP_VINFO_MAIN_EXIT (loop_vinfo),
> &incr_gsi,
> - &insert_after);
> + standard_iv_increment_position (loop, &incr_gsi, &insert_after);
>
> if (insert_after)
> gsi_insert_seq_after (&incr_gsi, stmts, GSI_NEW_STMT);
> --
> 2.43.0