[llvm-dev] generate vectorized code
Rail Shafigulin via llvm-dev
llvm-dev at lists.llvm.org
Fri Mar 18 14:43:30 PDT 2016
>
> I see vectorization happening on this example (see below).
>
>
>
>> Any help is appreciated.
>>
>>
>>>
>>> --
>>> Mehdi
>>>
>>
>>
>>
>> --
>> Rail Shafigulin
>> Software Engineer
>> Esencia Technologies
>>
>
> Forgot to attach a C file. Here it is:
>
> #define N 32
>
> int main () {
>
> int a[N], b[N];
> int c[N];
>
> for (int i = 0; i < N; ++i)
> c[i] = a[i] + b[i];
>
> int sum=0;
> for (int i = 0; i < N; ++i)
> sum += c[i];
>
> return sum;
> }
>
>
> This will be vectorized without any insertelement, here is a few lines
> extracted from the output of clang on this code:
>
> %wide.load8.6 = load <4 x i32>* %48, align 16, !tbaa !2
> %49 = add nsw <4 x i32> %wide.load8.6, %wide.load.6
> %50 = getelementptr inbounds [32 x i32]* %c, i64 0, i64 24
> %51 = bitcast i32* %50 to <4 x i32>*
> store <4 x i32> %49, <4 x i32>* %51, align 16, !tbaa !2
>
> Because you didn't write the example as I described it, i.e. taking
> integer, doing a few arithmetic and writing result to contiguous memory,
> the vectorizer will be able to load directly vectors from memory, operates
> on them, and store the results. For example try with the following C code:
>
> void foo (int a1, int a2, int a3, int a4, int b1, int b2, int b3, int b4,
> int *res) {
> res[0] = a1 + b1 * 2;
> res[1] = a2 + b2 * 2;
> res[2] = a3 + b3 * 2;
> res[3] = a4 + b4 * 2;
> }
>
>
> That's for the clang part, you can look at the vectorizer lit test to have
> examples of IR before/after vectorization.
>
> --
> Mehdi
>
Just out of curiosity how did you know that your foo code will produce
vectorized code? I tried code similar to yours without any multiplication
and no vectors were generated.
--
Rail Shafigulin
Software Engineer
Esencia Technologies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160318/f68d296b/attachment.html>
More information about the llvm-dev
mailing list