<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Yes, llvm will insert runtime checks.<br></div><div><br>On Mar 12, 2014, at 5:26 PM, Raul Silvera <<a href="mailto:rsilvera@google.com">rsilvera@google.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif">Even without wrapping around the end of the address space, without restrict you still have to worry about A and B overlapping on interesting ways. Will LLVM do some runtime dependence checks to discount such potential overlap? Just curious....</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Mar 12, 2014 at 5:01 PM, Arnold Schwaighofer <span dir="ltr"><<a href="mailto:aschwaighofer@apple.com" target="_blank">aschwaighofer@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Zinovy,<br>
<br>
to clarify: the code is vectorizable. But LLVM currently fails to prove it is.<br>
<div class="HOEnZb"><div class="h5"><br>
On Mar 12, 2014, at 3:50 PM, Arnold Schwaighofer <<a href="mailto:aschwaighofer@apple.com">aschwaighofer@apple.com</a>> wrote:<br>
<br>
> In order to vectorize code like this LLVM needs to prove that “A[i*7]” does not wrap in the address space. It fails to do so and so LLVM doesn’t vectorize this loop even if we try to force it.<br>
><br>
> The following loop will be vectorized if we force it:<br>
><br>
> int foo(int * A, int * B, int n, int k) {<br>
>  for (int i = 0; i < 1024; ++i)<br>
>    A[i] += B[i*k];<br>
> }<br>
><br>
> So will this loop:<br>
><br>
> int foo(int * restrict A, int * restrict B, int n, int k) {<br>
>  for (int i = 0; i < n; ++i)<br>
>    A[i] += B[i*k];<br>
> }<br>
><br>
> I will update the example.<br>
><br>
> Thanks,<br>
> Arnold<br>
><br>
> On Mar 12, 2014, at 1:54 PM, Nadav Rotem <<a href="mailto:nrotem@apple.com">nrotem@apple.com</a>> wrote:<br>
><br>
>> Hi Zinovy,<br>
>><br>
>> 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.<br>
>><br>
>> Thanks,<br>
>> Nadav<br>
>><br>
>> On Mar 12, 2014, at 3:34 AM, Zinovy Nis <<a href="mailto:zinovy.nis@gmail.com">zinovy.nis@gmail.com</a>> wrote:<br>
>><br>
>>> Hi,<br>
>>><br>
>>> I'm reading "<a href="http://llvm.org/docs/Vectorizers.html" target="_blank">http://llvm.org/docs/Vectorizers.html</a>" and have few question. Hope someone has answers on it.<br>
>>><br>
>>><br>
>>> The Loop Vectorizer can vectorize code that becomes a sequence of scalar instructions that scatter/gathers memory. (<a href="http://llvm.org/docs/Vectorizers.html#scatter-gather" target="_blank">http://llvm.org/docs/Vectorizers.html#scatter-gather</a>)<br>

>>><br>
>>> int foo(int *A, int *B, int n, int k) {<br>
>>>  for (int i = 0; i < n; ++i)<br>
>>>    A[i*7] += B[i*k];<br>
>>> }<br>
>>><br>
>>> I replaced "int *A"/"int *B" into "double *A"/"double *B" and then compiled the sample with<br>
>>><br>
>>> $> ./clang -Ofast -ffast-math test.c -std=c99 -march=core-avx2 -S -o bb.S  -fslp-vectorize-aggressive<br>
>>><br>
>>> and loop body looks like:<br>
>>><br>
>>> .LBB1_2:                                # %for.body<br>
>>>                                        # =>This Inner Loop Header: Depth=1<br>
>>>        cltq<br>
>>>        vmovsd  (%rsi,%rax,8), %xmm0<br>
>>>        movq    %r9, %r10<br>
>>>        sarq    $32, %r10<br>
>>>        vaddsd  (%rdi,%r10,8), %xmm0, %xmm0<br>
>>>        vmovsd  %xmm0, (%rdi,%r10,8)<br>
>>>        addq    %r8, %r9<br>
>>>        addl    %ecx, %eax<br>
>>>        decl    %edx<br>
>>>        jne     .LBB1_2<br>
>>><br>
>>> so vector instructions for scalars (vaddsd, vmovsd) were used in the loop and no real gather/scatter emitted.<br>
>>><br>
>>> The question is why this loop was not vectorized? Typo in docs?<br>
>>><br>
>>> _______________________________________________<br>
>>> LLVM Developers mailing list<br>
>>> <a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
>>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
>><br>
>> _______________________________________________<br>
>> LLVM Developers mailing list<br>
>> <a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
><br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><div><font size="4" face="arial black, sans-serif" style="background-color:rgb(0,0,0)" color="#b45f06"> Raúl E. Silvera </font></div>
<div><br></div></div>
</div>
</div></blockquote></body></html>