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; }
Created attachment 7502 [details] testcase
Confirmed.
Created attachment 7503 [details] patch. * tree-vectorizer.c (make_loop_iterate_ntimes): Set loop->nb_iterations. (vect_transform_loop_bound): Set loop->nb_iterations.
Subject: Bug 18400 CVSROOT: /cvs/gcc Module name: gcc Changes by: dorit@gcc.gnu.org 2004-11-14 18:30:36 Modified files: gcc : ChangeLog tree-vectorizer.c Log message: PR tree-opt/18400 * tree-vectorizer.c (make_loop_iterate_ntimes): Set loop->nb_iterations. (vect_transform_loop_bound): Set loop->nb_iterations. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.6334&r2=2.6335 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-vectorizer.c.diff?cvsroot=gcc&r1=2.29&r2=2.30
Fixed.
Subject: Bug 18400 CVSROOT: /cvs/gcc Module name: gcc Changes by: dorit@gcc.gnu.org 2004-11-14 20:44:52 Modified files: gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg/vect: pr18400.c pr18425.c Log message: 2004-11-14 Dorit Naishlos <dorit@il.ibm.com> PR tree-opt/18400 * gcc.dg/vect/pr18400.c: New test. 2004-11-14 Dorit Naishlos <dorit@il.ibm.com> Andrew Pinski <pinskia@physics.uc.edu> PR tree-opt/18425 * gcc.dg/vect/pr18425.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4599&r2=1.4600 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/vect/pr18400.c.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/vect/pr18425.c.diff?cvsroot=gcc&r1=NONE&r2=1.1