When forcing versioning for the vector profitability check I noticed
we use different niters for the peeling check than for the versioning one
leading to two branches, the 2nd being redundant.  The following makes
that consistent, also using the known not overflown number of latch
execution count.

Bootstrap / regtest pending on x86_64-unknown-linux-gnu.

Richard.

2017-06-21  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/81303
        * tree-vect-loop-manip.c (vect_loop_versioning): Build
        profitability check against LOOP_VINFO_NITERSM1.

Index: gcc/tree-vect-loop-manip.c
===================================================================
--- gcc/tree-vect-loop-manip.c  (revision 250386)
+++ gcc/tree-vect-loop-manip.c  (working copy)
@@ -2136,7 +2136,7 @@ vect_loop_versioning (loop_vec_info loop
   tree arg;
   profile_probability prob = profile_probability::likely ();
   gimple_seq gimplify_stmt_list = NULL;
-  tree scalar_loop_iters = LOOP_VINFO_NITERS (loop_vinfo);
+  tree scalar_loop_iters = LOOP_VINFO_NITERSM1 (loop_vinfo);
   bool version_align = LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT (loop_vinfo);
   bool version_alias = LOOP_REQUIRES_VERSIONING_FOR_ALIAS (loop_vinfo);
   bool version_niter = LOOP_REQUIRES_VERSIONING_FOR_NITERS (loop_vinfo);
@@ -2144,7 +2144,7 @@ vect_loop_versioning (loop_vec_info loop
   if (check_profitability)
     cond_expr = fold_build2 (GE_EXPR, boolean_type_node, scalar_loop_iters,
                             build_int_cst (TREE_TYPE (scalar_loop_iters),
-                                                      th));
+                                           th - 1));
 
   if (version_niter)
     vect_create_cond_for_niters_checks (loop_vinfo, &cond_expr);

Reply via email to