This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Do not vectorize loops that do not roll
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 19 Apr 2012 15:14:29 +0200 (CEST)
- Subject: [PATCH] Do not vectorize loops that do not roll
I noticed we vectorize
int objects[2];
void foo (int n)
{
int i;
for (i = 0; i < n; ++i)
objects[i] = i;
}
which is of course pointless (with a vectorization factor > 2).
The following patch avoids doing this.
Bootstrap & regtest pending on x86_64-unknown-linux-gnu.
Richard.
2012-04-19 Richard Guenther <rguenther@suse.de>
* tree-vect-loop.c (vect_analyze_loop_operations): Do not
vectorize loops that can never run more often than the
vectorization factor.
Index: gcc/tree-vect-loop.c
===================================================================
*** gcc/tree-vect-loop.c (revision 186589)
--- gcc/tree-vect-loop.c (working copy)
*************** vect_analyze_loop_operations (loop_vec_i
*** 1235,1240 ****
--- 1235,1241 ----
int min_scalar_loop_bound;
unsigned int th;
bool only_slp_in_loop = true, ok;
+ HOST_WIDE_INT max_niter;
if (vect_print_dump_info (REPORT_DETAILS))
fprintf (vect_dump, "=== vect_analyze_loop_operations ===");
*************** vect_analyze_loop_operations (loop_vec_i
*** 1407,1414 ****
"vectorization_factor = %d, niters = " HOST_WIDE_INT_PRINT_DEC,
vectorization_factor, LOOP_VINFO_INT_NITERS (loop_vinfo));
! if (LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)
! && (LOOP_VINFO_INT_NITERS (loop_vinfo) < vectorization_factor))
{
if (vect_print_dump_info (REPORT_UNVECTORIZED_LOCATIONS))
fprintf (vect_dump, "not vectorized: iteration count too small.");
--- 1408,1417 ----
"vectorization_factor = %d, niters = " HOST_WIDE_INT_PRINT_DEC,
vectorization_factor, LOOP_VINFO_INT_NITERS (loop_vinfo));
! if ((LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)
! && (LOOP_VINFO_INT_NITERS (loop_vinfo) < vectorization_factor))
! || ((max_niter = max_loop_iterations_int (loop)) != -1
! && max_niter < vectorization_factor))
{
if (vect_print_dump_info (REPORT_UNVECTORIZED_LOCATIONS))
fprintf (vect_dump, "not vectorized: iteration count too small.");