tree-vect-slp.c (vect_analyze_slp): When reduction group SLP discovery fails try...
authorRichard Biener <rguenther@suse.de>
Thu, 24 Oct 2019 06:19:01 +0000 (06:19 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 24 Oct 2019 06:19:01 +0000 (06:19 +0000)
2019-10-24  Richard Biener  <rguenther@suse.de>

* tree-vect-slp.c (vect_analyze_slp): When reduction group
SLP discovery fails try to handle the reduction as part
of SLP reduction discovery.

* gcc.dg/vect/slp-reduc-9.c: New testcase.

From-SVN: r277366

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/slp-reduc-9.c [new file with mode: 0644]
gcc/tree-vect-slp.c

index 0c81a1077afe8f78494961fa67d094eda06c24eb..9296d5d7236f4b5a5b43a728ec314ba2faf1fbb7 100644 (file)
@@ -1,3 +1,9 @@
+2019-10-24  Richard Biener  <rguenther@suse.de>
+
+       * tree-vect-slp.c (vect_analyze_slp): When reduction group
+       SLP discovery fails try to handle the reduction as part
+       of SLP reduction discovery.
+
 2019-10-23  Michael Meissner  <meissner@linux.ibm.com>
 
        * config/rs6000/rs6000-protos.h (rs6000_adjust_insn_length): New
index b3d44fa8ed9d71ebb6516f66cf1d06bf78ad114e..a752086d4cc957c05101b7920c24eae9881acebe 100644 (file)
@@ -1,3 +1,7 @@
+2019-10-24  Richard Biener  <rguenther@suse.de>
+
+       * gcc.dg/vect/slp-reduc-9.c: New testcase.
+
 2019-10-23  David Edelsohn  <dje.gcc@gmail.com>
 
        * gcc.target/powerpc/pr70010.c: Add -Wno-psabi.
diff --git a/gcc/testsuite/gcc.dg/vect/slp-reduc-9.c b/gcc/testsuite/gcc.dg/vect/slp-reduc-9.c
new file mode 100644 (file)
index 0000000..bee642e
--- /dev/null
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target vect_int_mult } */
+
+int
+bar (int *x, int a, int b, int n)
+{
+  x = __builtin_assume_aligned (x, __BIGGEST_ALIGNMENT__);
+  int sum1 = 0;
+  int sum2 = 0;
+  for (int i = 0; i < n; ++i)
+    {
+      /* Reduction chain vectorization fails here because of the
+         different operations but we can still vectorize both
+        reductions as SLP reductions, saving IVs.  */
+      sum1 += x[2*i] - a;
+      sum1 += x[2*i+1] * b;
+      sum2 += x[2*i] - b;
+      sum2 += x[2*i+1] * a;
+    }
+  return sum1 + sum2;
+}
+
+/* { dg-final { scan-tree-dump "Loop contains only SLP stmts" "vect" } } */
+/* { dg-final { scan-tree-dump "vectorizing stmts using SLP" "vect" } } */
+/* { dg-final { scan-tree-dump "vectorized 1 loops" "vect" } } */
index e1061ede061751f5fd6c55edb56671a854e7456e..0af51197a845d3a7b3495be3f2008ad7dfa8f623 100644 (file)
@@ -2271,14 +2271,18 @@ vect_analyze_slp (vec_info *vinfo, unsigned max_tree_size)
              {
                /* Dissolve reduction chain group.  */
                stmt_vec_info vinfo = first_element;
+               stmt_vec_info last = NULL;
                while (vinfo)
                  {
                    stmt_vec_info next = REDUC_GROUP_NEXT_ELEMENT (vinfo);
                    REDUC_GROUP_FIRST_ELEMENT (vinfo) = NULL;
                    REDUC_GROUP_NEXT_ELEMENT (vinfo) = NULL;
+                   last = vinfo;
                    vinfo = next;
                  }
                STMT_VINFO_DEF_TYPE (first_element) = vect_internal_def;
+               /* It can be still vectorized as part of an SLP reduction.  */
+               loop_vinfo->reductions.safe_push (last);
              }
        }