]> gcc.gnu.org Git - gcc.git/commitdiff
tree-optimization/114297 - SLP reduction with early break fix
authorRichard Biener <rguenther@suse.de>
Mon, 11 Mar 2024 13:58:57 +0000 (14:58 +0100)
committerRichard Biener <rguenther@suse.de>
Tue, 12 Mar 2024 07:16:56 +0000 (08:16 +0100)
The following makes sure to pass in the SLP node for the live stmts
we are generating the reduction epilogue for to
vect_create_epilog_for_reduction.  This follows the previous fix for
the non-SLP path.

PR tree-optimization/114297
* tree-vect-loop.cc (vectorizable_live_operation): Pass in the
live stmts SLP node to vect_create_epilog_for_reduction.

* gcc.dg/vect/vect-early-break_123-pr114297.c: New testcase.

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

diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_123-pr114297.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_123-pr114297.c
new file mode 100644 (file)
index 0000000..84487b7
--- /dev/null
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-add-options vect_early_break } */
+/* { dg-require-effective-target vect_early_break } */
+
+void h() __attribute__((__noreturn__));
+struct Extremes {
+  int w;
+  int h;
+};
+struct Extremes *array;
+int f(int num, int size1)
+{
+  int sw = 0, sh = 0;
+  for (int i = 0; i < size1; ++i)
+  {
+    if (num - i == 0)
+      h();
+    sw += array[i].w;
+    sh += array[i].h;
+  }
+  return (sw) +  (sh);
+}
index 20ee0aad9326cd457a4ffb64eb7bf042a0a4fe42..4375ebdcb493a90fd0501cbb4b07466077b525c3 100644 (file)
@@ -10729,17 +10729,18 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
         block, but we have to find an alternate exit first.  */
       if (LOOP_VINFO_EARLY_BREAKS (loop_vinfo))
        {
         block, but we have to find an alternate exit first.  */
       if (LOOP_VINFO_EARLY_BREAKS (loop_vinfo))
        {
+         slp_tree phis_node = slp_node ? slp_node_instance->reduc_phis : NULL;
          for (auto exit : get_loop_exit_edges (LOOP_VINFO_LOOP (loop_vinfo)))
            if (exit != LOOP_VINFO_IV_EXIT (loop_vinfo))
              {
                vect_create_epilog_for_reduction (loop_vinfo, reduc_info,
          for (auto exit : get_loop_exit_edges (LOOP_VINFO_LOOP (loop_vinfo)))
            if (exit != LOOP_VINFO_IV_EXIT (loop_vinfo))
              {
                vect_create_epilog_for_reduction (loop_vinfo, reduc_info,
-                                                 slp_node, slp_node_instance,
+                                                 phis_node, slp_node_instance,
                                                  exit);
                break;
              }
          if (LOOP_VINFO_EARLY_BREAKS_VECT_PEELED (loop_vinfo))
                                                  exit);
                break;
              }
          if (LOOP_VINFO_EARLY_BREAKS_VECT_PEELED (loop_vinfo))
-           vect_create_epilog_for_reduction (loop_vinfo, reduc_info, slp_node,
-                                             slp_node_instance,
+           vect_create_epilog_for_reduction (loop_vinfo, reduc_info,
+                                             phis_node, slp_node_instance,
                                              LOOP_VINFO_IV_EXIT (loop_vinfo));
        }
 
                                              LOOP_VINFO_IV_EXIT (loop_vinfo));
        }
 
This page took 0.08341 seconds and 5 git commands to generate.