diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 2eba6db9a911089665ab9d886904dfd9a081201c..88b03be713539a96ed05f82662b3856b9cf57f23 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+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
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3d63c57f308989536b22d5af91cc145b98478133..9552d201b5e4279200e6429d982557e5ffdf00be 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+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
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/x86_64/costmodel-pr30843.c b/gcc/testsuite/gcc.dg/vect/costmodel/x86_64/costmodel-pr30843.c
index 257d098cf8bc65fca396d20a71da0a810cd230bd..9a75b987d6d847f2b93ac5472bac4e08590f18dc 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/x86_64/costmodel-pr30843.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/x86_64/costmodel-pr30843.c
@@ -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" } } */
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index f065acc12f502bf21065661b9dbdce9e4c973a06..ecce348b39c8a09936c9082b2bb25d5ab6b62bf2 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -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)