vect: Use adjusted niters by considering peeling prologue
authorKewen Lin <linkw@linux.ibm.com>
Fri, 10 Jul 2020 02:58:28 +0000 (21:58 -0500)
committerKewen Lin <linkw@linux.ibm.com>
Fri, 10 Jul 2020 03:03:26 +0000 (22:03 -0500)
This patch is derived from the review of vector with length patch
series.  I relaxed the guard on LOOP_VINFO_PEELING_FOR_ALIGNMENT for
vector with length as Richard S.'s suggestion, then encountered one
failure from case gcc.dg/vect/vect-ifcvt-11.c with param
vect-partial-vector-usage=2 enablement run.  The root cause is that
we still use the original niters for the loop body vectorization,
it leads the access to go out of bound, instead we should use
LOOP_VINFO_NITERS which has been adjusted in vect_do_peeling by
considering the peeling number for prologue.

Bootstrapped/regtested on aarch64-linux-gnu and powerpc64le-linux-gnu.

gcc/ChangeLog:

* tree-vect-loop.c (vect_transform_loop): Use LOOP_VINFO_NITERS which
is adjusted by considering peeled prologue for non
vect_use_loop_mask_for_alignment_p cases.

gcc/tree-vect-loop.c

index 6ec1647..0a9be35 100644 (file)
@@ -8615,9 +8615,15 @@ vect_transform_loop (loop_vec_info loop_vinfo, gimple *loop_vectorized_call)
                             LOOP_VINFO_INT_NITERS (loop_vinfo) / lowest_vf);
          step_vector = build_one_cst (TREE_TYPE (niters));
        }
-      else
+      else if (vect_use_loop_mask_for_alignment_p (loop_vinfo))
        vect_gen_vector_loop_niters (loop_vinfo, niters, &niters_vector,
                                     &step_vector, niters_no_overflow);
+      else
+       /* vect_do_peeling subtracted the number of peeled prologue
+          iterations from LOOP_VINFO_NITERS.  */
+       vect_gen_vector_loop_niters (loop_vinfo, LOOP_VINFO_NITERS (loop_vinfo),
+                                    &niters_vector, &step_vector,
+                                    niters_no_overflow);
     }
 
   /* 1) Make sure the loop header has exactly two entries