diff mbox series

tree-optimization/117307 - STMT_VINFO_SLP_VECT_ONLY mis-computation

Message ID 20241028102836.D16E8137D4@imap1.dmz-prg2.suse.org
State New
Headers show
Series tree-optimization/117307 - STMT_VINFO_SLP_VECT_ONLY mis-computation | expand

Commit Message

Richard Biener Oct. 28, 2024, 10:28 a.m. UTC
STMT_VINFO_SLP_VECT_ONLY isn't properly computed as union of all
group members and when the group is later split due to duplicates
not all sub-groups inherit the flag.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR tree-optimization/117307
	* tree-vect-data-refs.cc (vect_analyze_data_ref_accesses):
	Properly compute STMT_VINFO_SLP_VECT_ONLY.  Set it on all
	parts of a split group.

	* gcc.dg/vect/pr117307.c: New testcase.
---
 gcc/testsuite/gcc.dg/vect/pr117307.c | 17 +++++++++++++++++
 gcc/tree-vect-data-refs.cc           | 19 +++++++++++++------
 2 files changed, 30 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/pr117307.c
diff mbox series

Patch

diff --git a/gcc/testsuite/gcc.dg/vect/pr117307.c b/gcc/testsuite/gcc.dg/vect/pr117307.c
new file mode 100644
index 00000000000..dc853d61706
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr117307.c
@@ -0,0 +1,17 @@ 
+/* { dg-do compile } */
+/* { dg-additional-options "-march=x86-64-v4" { target { x86_64-*-* i?86-*-* } } } */
+
+int a;
+float *b, *c;
+float d;
+void e() {
+  for (; a; a++) {
+    if (d) {
+      c[0] = b[0];
+      c[1] = b[1];
+    } else if (b[1])
+      c[0] = b[0] * 0;
+    b += 2;
+    c += 2;
+  }
+}
diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc
index 202af7a8952..54ad5c8f3dc 100644
--- a/gcc/tree-vect-data-refs.cc
+++ b/gcc/tree-vect-data-refs.cc
@@ -3565,12 +3565,15 @@  vect_analyze_data_ref_accesses (vec_info *vinfo,
 	  DR_GROUP_NEXT_ELEMENT (lastinfo) = stmtinfo_b;
 	  lastinfo = stmtinfo_b;
 
-	  STMT_VINFO_SLP_VECT_ONLY (stmtinfo_a)
-	    = !can_group_stmts_p (stmtinfo_a, stmtinfo_b, false);
+	  if (! STMT_VINFO_SLP_VECT_ONLY (stmtinfo_a))
+	    {
+	      STMT_VINFO_SLP_VECT_ONLY (stmtinfo_a)
+		= !can_group_stmts_p (stmtinfo_a, stmtinfo_b, false);
 
-	  if (dump_enabled_p () && STMT_VINFO_SLP_VECT_ONLY (stmtinfo_a))
-	    dump_printf_loc (MSG_NOTE, vect_location,
-			     "Load suitable for SLP vectorization only.\n");
+	      if (dump_enabled_p () && STMT_VINFO_SLP_VECT_ONLY (stmtinfo_a))
+		dump_printf_loc (MSG_NOTE, vect_location,
+				 "Load suitable for SLP vectorization only.\n");
+	    }
 
 	  if (init_b == init_prev
 	      && !to_fixup.add (DR_GROUP_FIRST_ELEMENT (stmtinfo_a))
@@ -3614,7 +3617,11 @@  vect_analyze_data_ref_accesses (vec_info *vinfo,
 	    {
 	      DR_GROUP_NEXT_ELEMENT (g) = DR_GROUP_NEXT_ELEMENT (next);
 	      if (!newgroup)
-		newgroup = next;
+		{
+		  newgroup = next;
+		  STMT_VINFO_SLP_VECT_ONLY (newgroup)
+		    = STMT_VINFO_SLP_VECT_ONLY (grp);
+		}
 	      else
 		DR_GROUP_NEXT_ELEMENT (ng) = next;
 	      ng = next;