]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/117041 - fix load classification of former grouped load
authorRichard Biener <rguenther@suse.de>
Wed, 9 Oct 2024 09:42:59 +0000 (11:42 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 9 Oct 2024 12:37:25 +0000 (14:37 +0200)
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.

gcc/testsuite/gcc.dg/torture/pr117041.c [new file with mode: 0644]
gcc/tree-vect-stmts.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr117041.c b/gcc/testsuite/gcc.dg/torture/pr117041.c
new file mode 100644 (file)
index 0000000..09dbbf4
--- /dev/null
@@ -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;
+}
index 43358767934612a9788c587f35f66e007faa8863..ad4a3141ab892f8d40e522e53149d4344685a3bc 100644 (file)
@@ -1991,21 +1991,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