https://gcc.gnu.org/g:81fd5bfdcbcaa5e2a841d793e1eecb045da02551

commit r14-10779-g81fd5bfdcbcaa5e2a841d793e1eecb045da02551
Author: Richard Biener <rguent...@suse.de>
Date:   Wed Oct 9 11:42:59 2024 +0200

    tree-optimization/117041 - fix load classification of former grouped load
    
    When we first detect a grouped load but later dis-associate it we
    only set DR_GROUP_FIRST_ELEMENT to NULL, indicating it is not a
    STMT_VINFO_GROUPED_ACCESS but leave DR_GROUP_NEXT_ELEMENT set.  This
    causes a stray DR_GROUP_NEXT_ELEMENT access in get_group_load_store_type
    to go wrong, indicating a load isn't single_element_p when it actually
    is, leading to wrong classification and an ICE.
    
            PR tree-optimization/117041
            * tree-vect-stmts.cc (get_group_load_store_type): Only
            check DR_GROUP_NEXT_ELEMENT for STMT_VINFO_GROUPED_ACCESS.
    
            * gcc.dg/torture/pr117041.c: New testcase.
    
    (cherry picked from commit 72c83f644dea755b4eba427aabde45f5d3694d9b)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr117041.c | 10 ++++++++++
 gcc/tree-vect-stmts.cc                  |  6 ++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr117041.c 
b/gcc/testsuite/gcc.dg/torture/pr117041.c
new file mode 100644
index 000000000000..09dbbf4c00ff
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr117041.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+
+unsigned short a;
+int b, c[7][6];
+int main() {
+  for (a = 0; a < 6; a++)
+    for (b = 5; b; b--)
+      c[a][b] = c[a+1][b];
+  return 0;
+}
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index a25ac53a4cd3..a78f1d0e2cc6 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -1993,21 +1993,23 @@ get_group_load_store_type (vec_info *vinfo, 
stmt_vec_info stmt_info,
   stmt_vec_info first_stmt_info;
   unsigned int group_size;
   unsigned HOST_WIDE_INT gap;
+  bool single_element_p;
   if (STMT_VINFO_GROUPED_ACCESS (stmt_info))
     {
       first_stmt_info = DR_GROUP_FIRST_ELEMENT (stmt_info);
       group_size = DR_GROUP_SIZE (first_stmt_info);
       gap = DR_GROUP_GAP (first_stmt_info);
+      single_element_p = (stmt_info == first_stmt_info
+                         && !DR_GROUP_NEXT_ELEMENT (stmt_info));
     }
   else
     {
       first_stmt_info = stmt_info;
       group_size = 1;
       gap = 0;
+      single_element_p = true;
     }
   dr_vec_info *first_dr_info = STMT_VINFO_DR_INFO (first_stmt_info);
-  bool single_element_p = (stmt_info == first_stmt_info
-                          && !DR_GROUP_NEXT_ELEMENT (stmt_info));
   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
 
   /* True if the vectorized statements would access beyond the last

Reply via email to