]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/102318 - reduction epilogue re-use
authorRichard Biener <rguenther@suse.de>
Wed, 15 Sep 2021 08:20:34 +0000 (10:20 +0200)
committerRichard Biener <rguenther@suse.de>
Wed, 15 Sep 2021 09:13:21 +0000 (11:13 +0200)
This refines the fix for PR102226 to do the mode conversion
from V2DI to VNx2DI separately from the sign-conversion, retaining
the signedness of the saved accumulator as before the original fix.

2021-09-15  Richard Biener <rguenther@suse.de>

PR tree-optimization/102318
* tree-vect-loop.c (vect_transform_cycle_phi): Revert
previous change and do the mode conversion separately from
the sign conversion.

* gcc.dg/vect/pr102318.c: New testcase.

gcc/testsuite/gcc.dg/vect/pr102318.c [new file with mode: 0644]
gcc/tree-vect-loop.c

diff --git a/gcc/testsuite/gcc.dg/vect/pr102318.c b/gcc/testsuite/gcc.dg/vect/pr102318.c
new file mode 100644 (file)
index 0000000..cc58efa
--- /dev/null
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+
+void
+vec_slp_int16_t (short int *restrict a, short int *restrict b, int n)
+{
+  short int x0 = b[0];
+  short int x1 = b[1];
+  short int x2 = b[2];
+  short int x3 = b[3];
+  for (int i = 0; i < n; ++i)
+  {
+    x0 += a[i * 4];
+    x1 += a[i * 4 + 1];
+    x2 += a[i * 4 + 2];
+    x3 += a[i * 4 + 3];
+  }
+  b[0] = x0;
+  b[1] = x1;
+  b[2] = x2;
+  b[3] = x3;
+}
index c9dcc647d2c325a1ab2a64151faa6b4fe25f2dc9..5a5b8da2e771a1dd204f22a6447eba96bb3b352c 100644 (file)
@@ -7755,11 +7755,20 @@ vect_transform_cycle_phi (loop_vec_info loop_vinfo,
                                                  (reduc_info),
                                                &stmts);
            }
-         if (!useless_type_conversion_p (vectype_out, TREE_TYPE (def)))
-           def = gimple_convert (&stmts, vectype_out, def);
+         /* The epilogue loop might use a different vector mode, like
+            VNx2DI vs. V2DI.  */
+         if (TYPE_MODE (vectype_out) != TYPE_MODE (TREE_TYPE (def)))
+           {
+             tree reduc_type = build_vector_type_for_mode
+               (TREE_TYPE (TREE_TYPE (def)), TYPE_MODE (vectype_out));
+             def = gimple_convert (&stmts, reduc_type, def);
+           }
          /* Adjust the input so we pick up the partially reduced value
             for the skip edge in vect_create_epilog_for_reduction.  */
          accumulator->reduc_input = def;
+         /* And the reduction could be carried out using a different sign.  */
+         if (!useless_type_conversion_p (vectype_out, TREE_TYPE (def)))
+           def = gimple_convert (&stmts, vectype_out, def);
          if (loop_vinfo->main_loop_edge)
            {
              /* While we'd like to insert on the edge this will split