When a loop like the following: ============================= #define N 8 int main () { int b[N] = {0,3,6,9,12,15,18,21}; int a[N]; int i; for (i = 0; i < N; i++){ a[i] = b[i]; } /* check results: */ for (i = 0; i < N; i++){ if (a[i] != b[i]) abort (); } return 0; } =============================
is compiled with: -O2 -ftree-vectorize -maltivec -funroll-loops it gets vectorized and then completely unrolled. The complete unroller looks at loop->nb_iterations to get the number of iterations; the problem is that loop- >nb_iterations is not always updated after vectorization, so the loop ends up being unrolled by 8 instead of by 2, and we get an execution failure. The following patch will fix the problem: Index: tree-vectorizer.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/tree-vectorizer.c,v retrieving revision 2.25 diff -c -3 -p -r2.25 tree-vectorizer.c *** tree-vectorizer.c 8 Nov 2004 13:54:41 -0000 2.25 --- tree-vectorizer.c 9 Nov 2004 13:16:54 -0000 *************** make_loop_iterate_ntimes (struct loop *l *** 635,640 **** --- 635,642 ---- if (vect_debug_stats (loop) || vect_debug_details (loop)) print_generic_expr (dump_file, cond_stmt, TDF_SLIM); + + loop->nb_iterations = niters; } *************** vect_transform_loop_bound (loop_vec_info *** 2881,2886 **** --- 2883,2890 ---- if (vect_debug_details (NULL)) print_generic_expr (dump_file, cond_stmt, TDF_SLIM); + + loop->nb_iterations = new_loop_bound; } -- Summary: wrong unrolling after vectorization due to invalid loop- >nb_iterations Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: tree-optimization AssignedTo: dorit at il dot ibm dot com ReportedBy: dorit at il dot ibm dot com CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: powerpc-apple-darwin7.0.0 GCC host triplet: powerpc-apple-darwin7.0.0 GCC target triplet: powerpc-apple-darwin7.0.0 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18400