http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49760
Summary: vectorization inhibited if indices are references Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: vincenzo.innoce...@cern.ch in this simple example only the third function vectorize even if they look semantically identical to me c++ -Wall -ftree-vectorizer-verbose=7 -Ofast -c test/testSoA.cpp gcc version 4.7.0 20110528 (experimental) (GCC) struct SoA { int * __restrict__ a; float * __restrict__ b; float * __restrict__ c; int size; }; struct SoB { int * __restrict__ a; float * __restrict__ b; int size; }; void foo(SoA const & in, SoB & out, int & k) { int N=in.size; for (int i=0; i!=N; ++i) { out.b[k] = in.a[i]+in.b[i]; out.a[k] = in.a[i]; ++k; } } void foo2(SoA const & in, SoB & out, int & k) { int j=k; for (int i=0; i!=in.size; ++i) { out.b[j] = in.a[i]+in.b[i]; out.a[j] = in.a[i]; ++j; } k = j; } void foo3(SoA const & in, SoB & out, int & k) { int j=k; int N=in.size; for (int i=0; i!=N; ++i) { out.b[j] = in.a[i]+in.b[i]; out.a[j] = in.a[i]; ++j; } k = j; } messages are test/testSoA.cpp:17: note: not vectorized: loop contains function calls or data references that cannot be analyzed test/testSoA.cpp:15: note: vectorized 0 loops in function. test/testSoA.cpp:26: note: not vectorized: number of iterations cannot be computed. test/testSoA.cpp:24: note: vectorized 0 loops in function. test/testSoA.cpp:38: note: cost model: epilogue peel iters set to vf/2 because loop iterations are unknown . ….. test/testSoA.cpp:38: note: Profitability threshold is 5 loop iterations. …. test/testSoA.cpp:38: note: created 5 versioning for alias checks. test/testSoA.cpp:38: note: LOOP VECTORIZED. test/testSoA.cpp:35: note: vectorized 1 loops in function. I will submit a different PR for the alias checks that looks not needed to me