https://gcc.gnu.org/g:46f07a7b7d4d5b391723a756e5fb7673800bac57
commit r17-1511-g46f07a7b7d4d5b391723a756e5fb7673800bac57 Author: Tamar Christina <[email protected]> Date: Fri Jun 12 11:56:54 2026 +0100 vect: use .VARYING for early break IV [PR125597] Similar to the mask control variable, this replaces and adds the temporary SSA var for early break scalar IVs with an IFN_VARYING until the replacement is done when we start vectorization. This prevents similar issues as the mask control variable when the IV expressions are folded. gcc/ChangeLog: PR tree-optimization/125597 * tree-vect-loop-manip.cc (vect_do_peeling): Create IFN_VARYING for early break scalar IV. * tree-vect-loop.cc (vect_update_ivs_after_vectorizer_for_early_breaks): Replace the IFN_VARYING with actual value. Diff: --- gcc/tree-vect-loop-manip.cc | 4 ++++ gcc/tree-vect-loop.cc | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc index 4a3444966acf..d2c854e16d44 100644 --- a/gcc/tree-vect-loop-manip.cc +++ b/gcc/tree-vect-loop-manip.cc @@ -3841,6 +3841,10 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree niters, tree nitersm1, { tree tmp_niters_vf = make_ssa_name (LOOP_VINFO_EARLY_BRK_IV_TYPE (loop_vinfo)); + gcall *tmp_call = gimple_build_call_internal (IFN_VARYING, 0); + gimple_call_set_lhs (tmp_call, tmp_niters_vf); + auto header_gsi = gsi_after_labels (loop->header); + gsi_insert_after (&header_gsi, tmp_call, GSI_SAME_STMT); if (!(LOOP_VINFO_NITERS_UNCOUNTED_P (loop_vinfo) && get_loop_exit_edges (loop).length () == 1) diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 51e7f05100de..4d9b691c3299 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -11079,6 +11079,11 @@ vect_update_ivs_after_vectorizer_for_early_breaks (loop_vec_info loop_vinfo) auto loop = LOOP_VINFO_LOOP (loop_vinfo); tree induc_var = niters_skip ? copy_ssa_name (phi_var) : phi_var; + /* Remove the existing dummy GIMPLE statement and just keep the def. */ + gimple *def = SSA_NAME_DEF_STMT (phi_var); + auto def_gsi = gsi_for_stmt (def); + gsi_remove (&def_gsi, true); + auto induction_phi = create_phi_node (induc_var, loop->header); tree induc_def = PHI_RESULT (induction_phi); @@ -11149,7 +11154,7 @@ vect_update_ivs_after_vectorizer_for_early_breaks (loop_vec_info loop_vinfo) gcc_assert (exit_bb); auto exit_gsi = gsi_after_labels (exit_bb); gsi_insert_seq_before (&exit_gsi, iv_stmts, GSI_SAME_STMT); - } + } /* Write the init_stmts in the loop-preheader block. */ auto psi = gsi_last_nondebug_bb (pe->src); gsi_insert_seq_after (&psi, init_stmts, GSI_LAST_NEW_STMT);
