[LLVMdev] Autovectorization questions

Nadav Rotem nrotem at apple.com
Wed Mar 12 13:54:58 PDT 2014


Hi Zinovy, 

The loop vectorizer probably decided that it was not profitable to vectorize the function. You can force the vectorization of the function by setting a low threshold. 

Thanks,
Nadav

On Mar 12, 2014, at 3:34 AM, Zinovy Nis <zinovy.nis at gmail.com> wrote:

> Hi,
> 
> I'm reading "http://llvm.org/docs/Vectorizers.html" and have few question. Hope someone has answers on it.
> 
> 
> The Loop Vectorizer can vectorize code that becomes a sequence of scalar instructions that scatter/gathers memory. (http://llvm.org/docs/Vectorizers.html#scatter-gather)
> 
> int foo(int *A, int *B, int n, int k) {
>   for (int i = 0; i < n; ++i)
>     A[i*7] += B[i*k];
> }
> 
> I replaced "int *A"/"int *B" into "double *A"/"double *B" and then compiled the sample with 
> 
> $> ./clang -Ofast -ffast-math test.c -std=c99 -march=core-avx2 -S -o bb.S  -fslp-vectorize-aggressive
> 
> and loop body looks like:
> 
> .LBB1_2:                                # %for.body
>                                         # =>This Inner Loop Header: Depth=1
>         cltq
>         vmovsd  (%rsi,%rax,8), %xmm0
>         movq    %r9, %r10
>         sarq    $32, %r10
>         vaddsd  (%rdi,%r10,8), %xmm0, %xmm0
>         vmovsd  %xmm0, (%rdi,%r10,8)
>         addq    %r8, %r9
>         addl    %ecx, %eax
>         decl    %edx
>         jne     .LBB1_2
> 
> so vector instructions for scalars (vaddsd, vmovsd) were used in the loop and no real gather/scatter emitted.
> 
> The question is why this loop was not vectorized? Typo in docs?
> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140312/69e0a8d8/attachment.html>


More information about the llvm-dev mailing list