I want to optimize my code for vectorization using
-msse2 -ftree-vectorizer-verbose=2.
I have the following simple code:
int main(){
int a[2048], b[2048], c[2048];
int i;
for (i=0; i<2048; i++){
b[i]=0;
c[i]=0;
}
for (i=0; i<2048; i++){
a[i] = b[i] + c[i];
}
return 0;
}
Why do I get the note
test.cpp:10: note: not vectorized: not enough data-refs in basic block.
Thanks!
For what it's worth, after adding an
asm volatile("": "+m"(a), "+m"(b), "+m"(c)::"memory");
near the end ofmain
, my copy ofgcc
emits this:So it recognised that the first loop was just doing
memset
to a couple arrays and the second loop was doing a vector addition, which it appropriately vectorised.I'm using
gcc version 4.9.0 20140521 (prerelease) (GCC)
.An older machine with
gcc version 4.7.2 (Debian 4.7.2-5)
also vectorises the loop, but in a different way. Your-ftree-vectorizer-verbose=2
setting makes it emit the following output:You probably goofed your compiler flags (I used
g++ -O3 -ftree-vectorize -ftree-vectorizer-verbose=2 -march=native foo155.cc -o foo155
to build) or have a really old compiler.remove the first loop and do this
int a[2048], b[2048], c[2048] = {0};
also try this tag
instead of