https://gcc.gnu.org/g:5020a4d96413ee79b01606e270336b4a758033b9

commit r15-11231-g5020a4d96413ee79b01606e270336b4a758033b9
Author: Richard Biener <[email protected]>
Date:   Sun Apr 26 11:16:33 2026 +0200

    tree-optimization/125019 - fix ICE with recurrence vectorization
    
    This fixes an oversight with the PR124677 fix.
    
            PR tree-optimization/125019
            * tree-vect-loop.cc (vectorizable_recurr): Properly guard
            against hitting last stmt when searching for the insertion
            place.
    
            * gcc.dg/pr125019.c: New testcase.
    
    (cherry picked from commit 0ecc55faf01e4ebd674d8e1a41712c9762c521aa)

Diff:
---
 gcc/testsuite/gcc.dg/pr125019.c | 12 ++++++++++++
 gcc/tree-vect-loop.cc           |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/pr125019.c b/gcc/testsuite/gcc.dg/pr125019.c
new file mode 100644
index 000000000000..0cdb5906de76
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr125019.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -fno-vect-cost-model -fno-tree-dce -fno-tree-pre" } */
+
+int a, b, c, d;
+void e(unsigned f) {
+  for (c = 0; c < 2; c++) {
+    b = d;
+    d = f;
+    for (a = 0; a < 2; a++)
+      ;
+  }
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index c3e5bbad4412..0098a582fa71 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -9804,7 +9804,7 @@ vectorizable_recurr (loop_vec_info loop_vinfo, 
stmt_vec_info stmt_info,
     }
   /* Skip inserted vectorized stmts for the latch definition.  We have to
      insert after those.  */
-  while (gimple_uid (gsi_stmt (gsi2)) == 0);
+  while (gsi_stmt (gsi2) && gimple_uid (gsi_stmt (gsi2)) == 0);
 
   for (unsigned i = 0; i < ncopies; ++i)
     {

Reply via email to