I'm trying to figure out why gcc 4.9.0 won't vectorize a simple array addition when using gcc 4.9.0, using -O -ftree-vectorize:
int a[256], b[256], c[256];
foo () {
int i;
a[:] = b[:] + c[:];
}
From looking at the assembler produced this loop hasn't been vectorized and with the -fopt-info-vec-all flag I get a lot of output telling me why vectorization failed, beginning with:
>testvec.c:5: note: ===== analyze_loop_nest =====
>testvec.c:5: note: === vect_analyze_loop_form ===
>testvec.c:5: note: not vectorized: control flow in loop.
>testvec.c:5: note: bad loop form.
which is puzzling, since there's not control flow in the loop. Vectorization of the for loop using standard array notation for the same operation works fine.
It looks like only the latest version of GCC (6.1) can vectorize your example:
http://melpon.org/wandbox/permlink/LOIweYNRRLXeJsZf