[Bug tree-optimization/123983] [16 Regression] wrong code at -O1 -ftree-vectorize on x86_64-pc-linux-gnu

2026-02-05 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123983

Richard Biener  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|ASSIGNED|RESOLVED

--- Comment #14 from Richard Biener  ---
Fixed.  Any fallout please open new bugs.

[Bug tree-optimization/123983] [16 Regression] wrong code at -O1 -ftree-vectorize on x86_64-pc-linux-gnu

2026-02-05 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123983

--- Comment #13 from GCC Commits  ---
The master branch has been updated by Richard Biener :

https://gcc.gnu.org/g:856ba1d7f786b0b5e53042e292296391ae1b0da4

commit r16-7324-g856ba1d7f786b0b5e53042e292296391ae1b0da4
Author: Richard Biener 
Date:   Thu Feb 5 11:09:59 2026 +0100

tree-optimization/123983 - only update IV on the requested edge

The following reverts back to only updating the IV after the
vectorized loop on the requested edge which avoids disrupting
live value vectorization.

PR tree-optimization/123983
* tree-vect-loop-manip.cc (vect_update_ivs_after_vectorizer):
Only update the PHI argument on the requested edge.

* gcc.dg/vect/vect-pr123983.c: New testcase.

[Bug tree-optimization/123983] [16 Regression] wrong code at -O1 -ftree-vectorize on x86_64-pc-linux-gnu

2026-02-05 Thread tnfchris at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123983

--- Comment #12 from Tamar Christina  ---
(In reply to Richard Biener from comment #11)
> (In reply to Tamar Christina from comment #9)
> > IMHO, the right fix is to have it not update out of loop uses that come from
> > a live value. The code was intended to fixup the IVs that were not live.
> > 
> > But will defer to you :)
> 
> I'll note the function takes an update_e edge, the edge to update IVs on. 
> It also only iterates over that edge destination PHIs.  As said, I'm going
> to see where it fails (eventually).

I'm away today so can't look it up at (back tomorrow)

But yes (from memory) it does get the edge, however because of the moving of
the call to
vect_update_ivs_after_vectorizer until after the skip_epilog edge we now can
have a value which that code copied into the skip epilog destination edge.

Previously it was OK to just update the destination of update_e, and when we
add the skip edge the correct value is copied in, because it copies from the
updated PHI. But now we do it in reverse.

And the reverse order was to make
vect_update_ivs_after_vectorizer_for_early_break not have to walk the edges
again to update them.

But a regression run should indeed point it out.

[Bug tree-optimization/123983] [16 Regression] wrong code at -O1 -ftree-vectorize on x86_64-pc-linux-gnu

2026-02-05 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123983

--- Comment #11 from Richard Biener  ---
(In reply to Tamar Christina from comment #9)
> IMHO, the right fix is to have it not update out of loop uses that come from
> a live value. The code was intended to fixup the IVs that were not live.
> 
> But will defer to you :)

I'll note the function takes an update_e edge, the edge to update IVs on.  It
also only iterates over that edge destination PHIs.  As said, I'm going to see
where it fails (eventually).

[Bug tree-optimization/123983] [16 Regression] wrong code at -O1 -ftree-vectorize on x86_64-pc-linux-gnu

2026-02-05 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123983

--- Comment #10 from Richard Biener  ---
Created attachment 63596
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63596&action=edit
patch

The reversal tests ok on x86_64, I've attached it for reference.  I'll see to
test on aarch64.

If you can quickly tell me a failing testcase that would be nice ;)

[Bug tree-optimization/123983] [16 Regression] wrong code at -O1 -ftree-vectorize on x86_64-pc-linux-gnu

2026-02-05 Thread tnfchris at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123983

--- Comment #9 from Tamar Christina  ---
IMHO, the right fix is to have it not update out of loop uses that come from a
live value. The code was intended to fixup the IVs that were not live.

But will defer to you :)

[Bug tree-optimization/123983] [16 Regression] wrong code at -O1 -ftree-vectorize on x86_64-pc-linux-gnu

2026-02-05 Thread tnfchris at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123983

--- Comment #8 from Tamar Christina  ---
(In reply to Richard Biener from comment #7)
> This is caused by r16-5780-g65a3849eb46df2 which does this semantic change
> in the following hunk and reverting this fixes the issue - the IV is then
> correctly only updated on the edge to the epilog, not on the use for the
> live operation.
> 
> I'm testing reversal of that hunk.
> 
> @@ -2419,8 +2434,15 @@ vect_update_ivs_after_vectorizer (loop_vec_info
> loop_vinf
> o,
>   gsi_insert_seq_before (&last_gsi, new_stmts, GSI_SAME_STMT);
> }
>  
> -  /* Fix phi expressions in the successor bb.  */
> -  adjust_phi_and_debug_stmts (phi1, update_e, ni_name);
> +  /* Fix phi expressions in all out of loop bb.  */
> +  imm_use_iterator imm_iter;
> +  gimple *use_stmt;
> +  use_operand_p use_p;
> +  tree ic_var = PHI_ARG_DEF_FROM_EDGE (phi1, update_e);
> +  FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, ic_var)
> +   if (!flow_bb_inside_loop_p (loop, gimple_bb (use_stmt)))
> + FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
> +   SET_USE (use_p, ni_name);
>  }
>  }

That doesn't sound quite right to me and is probably going to fail. The reason
for the change was because when we add a skip_epilog to the merge block we can
introduce a block which goes to an exit which has copied the live values from
the loop it was copied from.

This value is out of date, as if we skip the epilogue it can't use a value
derived from the epilog.  So the loop was added to update those out of loop
uses.

[Bug tree-optimization/123983] [16 Regression] wrong code at -O1 -ftree-vectorize on x86_64-pc-linux-gnu

2026-02-05 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123983

--- Comment #7 from Richard Biener  ---
This is caused by r16-5780-g65a3849eb46df2 which does this semantic change
in the following hunk and reverting this fixes the issue - the IV is then
correctly only updated on the edge to the epilog, not on the use for the
live operation.

I'm testing reversal of that hunk.

@@ -2419,8 +2434,15 @@ vect_update_ivs_after_vectorizer (loop_vec_info
loop_vinf
o,
  gsi_insert_seq_before (&last_gsi, new_stmts, GSI_SAME_STMT);
}

-  /* Fix phi expressions in the successor bb.  */
-  adjust_phi_and_debug_stmts (phi1, update_e, ni_name);
+  /* Fix phi expressions in all out of loop bb.  */
+  imm_use_iterator imm_iter;
+  gimple *use_stmt;
+  use_operand_p use_p;
+  tree ic_var = PHI_ARG_DEF_FROM_EDGE (phi1, update_e);
+  FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, ic_var)
+   if (!flow_bb_inside_loop_p (loop, gimple_bb (use_stmt)))
+ FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
+   SET_USE (use_p, ni_name);
 }
 }

[Bug tree-optimization/123983] [16 Regression] wrong code at -O1 -ftree-vectorize on x86_64-pc-linux-gnu

2026-02-05 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123983

Richard Biener  changed:

   What|Removed |Added

 CC||tnfchris at gcc dot gnu.org

--- Comment #6 from Richard Biener  ---
(In reply to Richard Biener from comment #5)
> It's the IV updating code for the epilog that is wrong now.  It effectively
> throws away the vector computation of 'c', now on both the path to
> the epilog and the edge skipping it while GCC

... while GCC 15 did so only on the path to the epilog.

This is the case where that is _not_ the same because the live value
is that after the decrement of the IV and the continuation value is
the one before it.  This was caused by Tamars changes, but I'll see to
try understand this.

[Bug tree-optimization/123983] [16 Regression] wrong code at -O1 -ftree-vectorize on x86_64-pc-linux-gnu

2026-02-05 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123983

--- Comment #5 from Richard Biener  ---
It's the IV updating code for the epilog that is wrong now.  It effectively
throws away the vector computation of 'c', now on both the path to
the epilog and the edge skipping it while GCC

[Bug tree-optimization/123983] [16 Regression] wrong code at -O1 -ftree-vectorize on x86_64-pc-linux-gnu

2026-02-05 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123983

Richard Biener  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |rguenth at gcc dot 
gnu.org
 Status|NEW |ASSIGNED

--- Comment #4 from Richard Biener  ---
Mine.

[Bug tree-optimization/123983] [16 Regression] wrong code at -O1 -ftree-vectorize on x86_64-pc-linux-gnu

2026-02-04 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123983

Andrew Pinski  changed:

   What|Removed |Added

   Priority|P3  |P1