GCC can definitely vectorize. Suppose you have a reduc.c file with the contents:
int foo(int *x, int N) { int acc, i; for( i = 0; i < N; ++i ) { acc += x[i]; } return acc; }
Compile it (I used gcc 4.7.2) with the command line:
$ gcc -O3 -S reduc.c -ftree-vectorize -msse2
Now you can see the vectorized loop in assembler.
In addition, you can enable the detailed output of the vector, say, with
$ gcc -O3 -S reduc.c -ftree-vectorize -msse2 -ftree-vectorizer-verbose=1
You will now receive a console report:
Analyzing loop at reduc.c:5 Vectorizing loop at reduc.c:5 5: LOOP VECTORIZED. reduc.c:1: note: vectorized 1 loops in function.
Check out the white papers for a better understanding of cases where the GCC can and cannot vectorize.
Konstantin Vladimirov
source share