On 10/4/2012 8:20 AM, Nicklas Bo Jensen wrote:
Hi,
I'm trying to use the autovectorizer in gcc 4.7.2. However I'm getting
bad data references in the .vect comments generated using
-ftree-vectorizer-verbose=, even though I have used restrict on all
arrays. Its a reference with two arrays where one array is used to
index the other: array1[array2[index]]. I don't see how this should
not be vectorizable as we only read from the arrays.
Is this not supported or is there some clever way to rewrite this?
Example:
int foo(int * restrict array1, int * restrict array2) {
int res = 0;
for (int i = 0; i < 50000; i++) {
int v = array2[array1[i]]; //This gives bad data reference comment
in .vect file.
res += v * v;
}
return res;
}
You would require "simulated gather" to take advantage of SSE4 or AVX
scalar to vector register moves (so your -march setting enters in).
restrict has no bearing here, as you modify only res and v which have
segregated scope from the data regions accessed by pointer.
Intel compilers tend to require pragma stuff such as #pragma simd
reduction(+: res) to promote "vectorization" using simulated gather.
Evidently, such idioms are typically used with floating point data types
and -ffast-math or equivalent options to enable associative-math.
--
Tim Prince