https://gcc.gnu.org/g:8bb7234a86f3432658f9fa29d7957d1d0c929832

commit r16-2346-g8bb7234a86f3432658f9fa29d7957d1d0c929832
Author: Richard Biener <rguent...@suse.de>
Date:   Fri Jul 18 08:28:59 2025 +0200

    tree-optimization/121126 - properly verify live LC PHIs
    
    The following makes sure we analyze live LC PHIs not part of
    a double reduction.
    
            PR tree-optimization/121126
            * tree-vect-stmts.cc (vect_analyze_stmt): Analyze the
            live lane extract for LC PHIs that are vect_internal_def.
    
            * gcc.dg/vect/pr121126.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr121126.c | 30 ++++++++++++++++++++++++++++++
 gcc/tree-vect-stmts.cc               |  3 ++-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/vect/pr121126.c 
b/gcc/testsuite/gcc.dg/vect/pr121126.c
new file mode 100644
index 000000000000..ae6603bb1e5f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr121126.c
@@ -0,0 +1,30 @@
+/* { dg-additional-options "--param vect-partial-vector-usage=2" } */
+
+#include "tree-vect.h"
+
+unsigned char a;
+unsigned b;
+int r[11];
+static void __attribute__((noipa))
+c(int e, unsigned s[][11][11])
+{
+  for (int u = -(e ? 2000424973 : 0) - 2294542319; u < 7; u += 4)
+    for (int x = 0; x < 300000011; x += 4)
+      for (int y = 0; y < (0 < s[u][4][1]) + 11; y += 3) {
+        a = a ?: 1;
+        b = r[2];
+      }
+}
+long long ab;
+int e = 1;
+unsigned s[11][11][11];
+int main()
+{
+  check_vect ();
+  for (int t = 0; t < 11; ++t)
+    r[t] = 308100;
+  c(e,s);
+  ab = b;
+  if (ab != 308100)
+    __builtin_abort ();
+}
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index f0d310583723..2e9b3d2e6863 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -13378,7 +13378,8 @@ vect_analyze_stmt (vec_info *vinfo,
       need extra handling, except for vectorizable reductions.  */
   if (!bb_vinfo
       && STMT_VINFO_TYPE (stmt_info) != reduc_vec_info_type
-      && STMT_VINFO_TYPE (stmt_info) != lc_phi_info_type
+      && (STMT_VINFO_TYPE (stmt_info) != lc_phi_info_type
+         || STMT_VINFO_DEF_TYPE (stmt_info) == vect_internal_def)
       && (!node->ldst_lanes || SLP_TREE_CODE (node) == VEC_PERM_EXPR)
       && !can_vectorize_live_stmts (as_a <loop_vec_info> (vinfo),
                                    node, node_instance,

Reply via email to