]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end: fill in reduction PHI for all alt exits [PR113178]
authorTamar Christina <tamar.christina@arm.com>
Fri, 12 Jan 2024 15:26:29 +0000 (15:26 +0000)
committerTamar Christina <tamar.christina@arm.com>
Fri, 12 Jan 2024 15:31:48 +0000 (15:31 +0000)
When we have a loop with more than 2 exits and a reduction I forgot to fill in
the PHI value for all alternate exits.

All alternate exits use the same PHI value so we should loop over the new
PHI elements and copy the value across since we call the reduction calculation
code only once for all exits.  This was normally covered up by earlier parts of
the compiler rejecting loops incorrectly (which has been fixed now).

Note that while I can use the loop in all cases, the reason I separated out the
main and alt exit is so that if you pass the wrong edge the macro will assert.

gcc/ChangeLog:

PR tree-optimization/113178
* tree-vect-loop.cc (vect_create_epilog_for_reduction): Fill in all
alternate exits.

gcc/testsuite/ChangeLog:

PR tree-optimization/113178
* gcc.dg/vect/vect-early-break_101-pr113178.c: New test.
* gcc.dg/vect/vect-early-break_102-pr113178.c: New test.

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

diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_101-pr113178.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_101-pr113178.c
new file mode 100644 (file)
index 0000000..8b91112
--- /dev/null
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-add-options vect_early_break } */
+/* { dg-require-effective-target vect_early_break } */
+/* { dg-require-effective-target vect_int } */
+
+struct PixelWeight {
+  int m_SrcStart;
+  int m_Weights[16];
+};
+char h;
+void f(struct PixelWeight *pPixelWeights) {
+    int dest_g_m;
+    long tt;
+    for (int j = 0; j < 16; j++) {
+      int *p = 0;
+      if (j < pPixelWeights->m_SrcStart)
+        p = tt ? &pPixelWeights->m_Weights[0] : 0;
+      int pWeight = *p;
+      dest_g_m += pWeight;
+    }
+    h = dest_g_m;
+}
diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_102-pr113178.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_102-pr113178.c
new file mode 100644 (file)
index 0000000..ad7582e
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-add-options vect_early_break } */
+/* { dg-require-effective-target vect_early_break } */
+/* { dg-require-effective-target vect_int } */
+/* { dg-additional-options "-std=gnu99 -fpermissive -fgnu89-inline -Ofast -fprofile-generate -w" } */
+
+extern int replace_reg_with_saved_mem_i, replace_reg_with_saved_mem_nregs,
+    replace_reg_with_saved_mem_mem_1;
+replace_reg_with_saved_mem_mode() {
+  if (replace_reg_with_saved_mem_i)
+    return;
+  while (++replace_reg_with_saved_mem_i < replace_reg_with_saved_mem_nregs)
+    if (replace_reg_with_saved_mem_i)
+      break;
+  if (replace_reg_with_saved_mem_i)
+    if (replace_reg_with_saved_mem_mem_1)
+      adjust_address_1();
+  replace_reg_with_saved_mem_mem_1 ? fancy_abort() : 0;
+}
index 0f4a557fe2339b095f6ae833f8f0ef847fdf7f47..44022bf94480988bdb370d85924fc0d142963b2d 100644 (file)
@@ -6247,7 +6247,13 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
          phi = create_phi_node (new_def, exit_bb);
          if (j)
            def = gimple_get_lhs (vec_stmts[j]);
-         SET_PHI_ARG_DEF (phi, loop_exit->dest_idx, def);
+         if (LOOP_VINFO_IV_EXIT (loop_vinfo) == loop_exit)
+           SET_PHI_ARG_DEF (phi, loop_exit->dest_idx, def);
+         else
+           {
+             for (unsigned k = 0; k < gimple_phi_num_args (phi); k++)
+               SET_PHI_ARG_DEF (phi, k, def);
+           }
          new_def = gimple_convert (&stmts, vectype, new_def);
          reduc_inputs.quick_push (new_def);
        }