https://gcc.gnu.org/g:bbe47a2d763d14de94c1e98104e2fa553783972a

commit r14-11000-gbbe47a2d763d14de94c1e98104e2fa553783972a
Author: Richard Biener <rguent...@suse.de>
Date:   Mon Oct 28 09:52:08 2024 +0100

    tree-optimization/117307 - STMT_VINFO_SLP_VECT_ONLY mis-computation
    
    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.
    
            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.
    
    (cherry picked from commit 19722308a286d9a00eead8ac82b948da8c4ca38b)

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr117307.c | 17 +++++++++++++++++
 gcc/tree-vect-data-refs.cc           | 19 +++++++++++++------
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/pr117307.c 
b/gcc/testsuite/gcc.dg/vect/pr117307.c
new file mode 100644
index 000000000000..dc853d617065
--- /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 c531079d3bbf..b1bacf8b2792 100644
--- a/gcc/tree-vect-data-refs.cc
+++ b/gcc/tree-vect-data-refs.cc
@@ -3552,12 +3552,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))
@@ -3601,7 +3604,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;

Reply via email to