tree-optimization/95219 - improve IV selection for induction
authorRichard Biener <rguenther@suse.de>
Wed, 20 May 2020 07:22:58 +0000 (09:22 +0200)
committerRichard Biener <rguenther@suse.de>
Wed, 20 May 2020 12:09:26 +0000 (14:09 +0200)
This improves code generation with SSE2 for the testcase by
making sure to only generate a single IV when the group size
is a multiple of the vector size.  It also adjusts the testcase
which was passing before.

2020-05-20  Richard Biener  <rguenther@suse.de>

PR tree-optimization/95219
* tree-vect-loop.c (vectorizable_induction): Reduce
group_size before computing the number of required IVs.

* gcc.dg/vect/costmodel/x86_64/costmodel-pr30843.c: Adjust.

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/costmodel/x86_64/costmodel-pr30843.c
gcc/tree-vect-loop.c

index 2eba6db..88b03be 100644 (file)
@@ -1,5 +1,11 @@
 2020-05-20  Richard Biener  <rguenther@suse.de>
 
+       PR tree-optimization/95219
+       * tree-vect-loop.c (vectorizable_induction): Reduce
+       group_size before computing the number of required IVs.
+
+2020-05-20  Richard Biener  <rguenther@suse.de>
+
        PR middle-end/95231
        * tree-inline.c (remap_gimple_stmt): Revert adjusting
        COND_EXPR and VEC_COND_EXPR for a -fnon-call-exception boundary.
index 3d63c57..9552d20 100644 (file)
@@ -1,5 +1,11 @@
 2020-05-20  Richard Biener  <rguenther@suse.de>
 
+       PR tree-optimization/95219
+       * tree-vect-loop.c (vectorizable_induction): Reduce
+       group_size before computing the number of required IVs.
+
+2020-05-20  Richard Biener  <rguenther@suse.de>
+
        PR middle-end/95231
        * g++.dg/other/pr95231.C: New testcase.
 
index 257d098..9a75b98 100644 (file)
@@ -20,4 +20,6 @@ void dacP98FillRGBMap (unsigned char *pBuffer)
     }
 }
 
-/* { dg-final { scan-tree-dump-times "vectorization not profitable" 1 "vect" { target vect_interleave } } } */
+/* Even with SSE2 we should only generate one IV for the induction.  */
+/* { dg-final { scan-tree-dump-times "# vect_vec_iv" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" } } */
index f065acc..ecce348 100644 (file)
@@ -7528,7 +7528,13 @@ vectorizable_induction (loop_vec_info loop_vinfo,
       unsigned group_size = SLP_TREE_SCALAR_STMTS (slp_node).length ();
       unsigned nvects = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node);
       unsigned elts = const_nunits * nvects;
-      unsigned nivs = least_common_multiple (group_size,
+      /* Compute the number of distinct IVs we need.  First reduce
+        group_size if it is a multiple of const_nunits so we get
+        one IV for a group_size of 4 but const_nunits 2.  */
+      unsigned group_sizep = group_size;
+      if (group_sizep % const_nunits == 0)
+       group_sizep = group_sizep / const_nunits;
+      unsigned nivs = least_common_multiple (group_sizep,
                                             const_nunits) / const_nunits;
       gcc_assert (elts % group_size == 0);
       tree elt = init_expr;
@@ -7576,6 +7582,12 @@ vectorizable_induction (loop_vec_info loop_vinfo,
 
          SLP_TREE_VEC_STMTS (slp_node).quick_push (induction_phi_info);
        }
+      /* Fill up to the number of vectors we need for the whole group.  */
+      nivs = least_common_multiple (group_size,
+                                   const_nunits) / const_nunits;
+      for (; ivn < nivs; ++ivn)
+       SLP_TREE_VEC_STMTS (slp_node)
+         .quick_push (SLP_TREE_VEC_STMTS (slp_node)[0]);
 
       /* Re-use IVs when we can.  */
       if (ivn < nvects)