]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/118269 - SLP reduction chain and early breaks
authorRichard Biener <rguenther@suse.de>
Tue, 7 Jan 2025 10:15:43 +0000 (11:15 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 8 Jan 2025 07:21:50 +0000 (08:21 +0100)
When we create the SLP reduction chain epilogue for the PHIs for
the early exit we fail to properly classify the reduction as SLP
reduction chain.  The following fixes the corresponding checks.

PR tree-optimization/118269
* tree-vect-loop.cc (vect_create_epilog_for_reduction):
Use the correct stmt for the REDUC_GROUP_FIRST_ELEMENT lookup.

* gcc.dg/vect/vect-early-break_131-pr118269.c: New testcase.

gcc/testsuite/gcc.dg/vect/vect-early-break_131-pr118269.c [new file with mode: 0644]
gcc/tree-vect-loop.cc

diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_131-pr118269.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_131-pr118269.c
new file mode 100644 (file)
index 0000000..5f7abce
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-add-options vect_early_break } */
+/* { dg-additional-options "-O3" } */
+
+short g_113;
+int func_1_l_1273, func_1_l_1370, func_1_l_1258;
+void func_1() {
+  int l_1375;
+  for (; l_1375; l_1375--) {
+    for (; func_1_l_1370;)
+      ;
+    func_1_l_1273 &= !0;
+    func_1_l_1273 &= g_113;
+    if (func_1_l_1258)
+      break;
+  }
+}
index 2b9d5956635752df790725eb7713fbf81b7dcee6..bb1138bfcfba11b9fd16f9dd321ac0aadf33663c 100644 (file)
@@ -6039,7 +6039,9 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
      # b1 = phi <b2, b0>
      a2 = operation (a1)
      b2 = operation (b1)  */
-  bool slp_reduc = (slp_node && !REDUC_GROUP_FIRST_ELEMENT (stmt_info));
+  bool slp_reduc
+    = (slp_node
+       && !REDUC_GROUP_FIRST_ELEMENT (STMT_VINFO_REDUC_DEF (reduc_info)));
   bool direct_slp_reduc;
   tree induction_index = NULL_TREE;
 
@@ -6331,7 +6333,7 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
      a multiple of the SLP group size.
 
      The same is true if we couldn't use a single defuse cycle.  */
-  if (REDUC_GROUP_FIRST_ELEMENT (stmt_info)
+  if (REDUC_GROUP_FIRST_ELEMENT (STMT_VINFO_REDUC_DEF (reduc_info))
       || direct_slp_reduc
       || (slp_reduc
          && constant_multiple_p (TYPE_VECTOR_SUBPARTS (vectype), group_size))
@@ -6632,7 +6634,7 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
       if (slp_node)
        {
          tree initial_value = NULL_TREE;
-         if (REDUC_GROUP_FIRST_ELEMENT (stmt_info))
+         if (REDUC_GROUP_FIRST_ELEMENT (STMT_VINFO_REDUC_DEF (reduc_info)))
            initial_value = reduc_info->reduc_initial_values[0];
          neutral_op = neutral_op_for_reduction (TREE_TYPE (vectype), code,
                                                 initial_value, false);