[gcc r16-9245] vect: use .VARYING for early break IV [PR125597]

Tamar Christina via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:a3a7c2da0508ceec0bd73994f62f9a4cb1ab3649

commit r16-9245-ga3a7c2da0508ceec0bd73994f62f9a4cb1ab3649
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.
    
    (cherry picked from commit 46f07a7b7d4d5b391723a756e5fb7673800bac57)

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 f7a0e8500435..c217fd1390f0 100644
--- a/gcc/tree-vect-loop-manip.cc
+++ b/gcc/tree-vect-loop-manip.cc
@@ -3778,6 +3778,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 c3757de38e18..521975e6a2cc 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -11083,6 +11083,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);
 
@@ -11153,7 +11158,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);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.