The previous fix breaks in the degenerate case when the discovered
last_stmt is equal to the first stmt in the block since then we
undo a required stmt advancement.

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

        PR tree-optimization/115652
        * tree-vect-slp.cc (vect_schedule_slp_node): Only insert
        at the start of the block if that strictly dominates
        the discovered dependent stmt.
---
 gcc/tree-vect-slp.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index 896ea6dc14c..ce214dd652e 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -9752,7 +9752,8 @@ vect_schedule_slp_node (vec_info *vinfo,
              {
                gimple_stmt_iterator si2
                  = gsi_after_labels (LOOP_VINFO_LOOP (loop_vinfo)->header);
-               if (vect_stmt_dominates_stmt_p (last_stmt, *si2))
+               if (last_stmt != *si2
+                   && vect_stmt_dominates_stmt_p (last_stmt, *si2))
                  si = si2;
              }
        }
-- 
2.43.0

Reply via email to