<div dir="ltr">I got it , thank you<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Nov 4, 2013 at 12:04 AM, 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">Hi Sarah,<br>
<br>
the loop vectorizer runs not on the C code but on LLVM IR this c code was lowered to. Before the loop vectorizer runs many other optimization change the shape of this IR.<br>
<br>
You can see in the LLVM IR you referenced below, a preceding LLVM IR transformation has change your loop from:<br>
<div class="im"><br>
> for(int k=20;k<50;k++)<br>
>      dataY[k] = dataY[k-1];<br>
<br>
</div><div class="im">to<br>
<br>
>   int a = d[19];<br>
>   for(int k = 20; k < 50; k++)<br>
>     dataY[k] = a;<br>
<br>
<br>
</div>which is allowed because they are semantically equivalent and beneficial because we safe many loads.<br>
<br>
We can vectorize the latter loop. You can see in the debug output there is no load in the loop once the loop vectorizer gets to see it:<br>
<div class="im"><br>
> And the debug prints:<br>
> LV: Checking a loop in "main"<br>
> LV: Found a loop: for.body4<br>
> LV: Found an induction variable.<br>
</div>> LV: Found a write-only loop! // <<<< Write-only.<br>
<div class="im">> LV: We can vectorize this loop!<br>
> ...<br>
> LV: Vectorization is possible but not beneficial.<br>
<br>
<br>
<br>
</div>This is not a bug but a great example of how one optimization can enable another.<br>
<br>
Best,<br>
Arnold<br>
<div class="HOEnZb"><div class="h5"><br>
On Nov 3, 2013, at 10:39 AM, Sara Elshobaky <<a href="mailto:sara.elshobaky@gmail.com">sara.elshobaky@gmail.com</a>> wrote:<br>
<br>
> Actually what I meant in my original loop, that there is a dependency between every two consecutive iterations. So, how the loop vectorizer says ‘we can vectorize this loop’?<br>
> for(int k=20;k<50;k++)<br>
>      dataY[k] = dataY[k-1];<br>
><br>
><br>
> From: Henrique Santos [mailto:<a href="mailto:henrique.nazare.santos@gmail.com">henrique.nazare.santos@gmail.com</a>]<br>
> Sent: Sunday, November 03, 2013 4:28 PM<br>
> To: Sara Elshobaky<br>
> Cc: <<a href="mailto:llvmdev@cs.uiuc.edu">llvmdev@cs.uiuc.edu</a>><br>
> Subject: Re: [LLVMdev] loop vectorizer issue<br>
><br>
> Notice that the code you provided, for globals and stack allocations, at least,<br>
> is semantically equivalent to:<br>
><br>
>   int a = d[19];<br>
>   for(int k = 20; k < 50; k++)<br>
>     dataY[k] = a;<br>
><br>
> Like so, the load you see missing was redundant, probably hoisted by GVN/PRE<br>
> and replaced with "%.pre".<br>
><br>
> H.<br>
><br>
><br>
><br>
> On Sun, Nov 3, 2013 at 11:26 AM, Sara Elshobaky <<a href="mailto:sara.elshobaky@gmail.com">sara.elshobaky@gmail.com</a>> wrote:<br>
> Hello,<br>
> I was trying to trace the Loop vectorizer of the LLVM, I wrote a simple loop with a clear dependency.<br>
> But found that the debug shows that ‘we can vectorize this loop’<br>
><br>
> Here you are my  loop with dependency:<br>
> for(int k=20;k<50;k++)<br>
>      dataY[k] = dataY[k-1];<br>
><br>
> And the debug prints:<br>
> LV: Checking a loop in "main"<br>
> LV: Found a loop: for.body4<br>
> LV: Found an induction variable.<br>
> LV: Found a write-only loop!<br>
> LV: We can vectorize this loop!<br>
> ...<br>
> LV: Vectorization is possible but not beneficial.<br>
><br>
> From the LLVM IR, it contains only one ‘store’ instruction with ‘%.pre’. Seems that no ‘load’ instruction prevented the Vectorizer to detect dependency.<br>
> Is that a bug, or I’m missing something? Please advice<br>
><br>
> for.body4:                                        ; preds = %for.body4, %for.cond2.preheader<br>
>   %k.030 = phi i32 [ 20, %for.cond2.preheader ], [ %inc8, %for.body4 ]<br>
>   %arrayidx6 = getelementptr inbounds i32* %0, i32 %k.030<br>
>   store i32 %.pre, i32* %arrayidx6, align 4, !tbaa !0<br>
>   %inc8 = add nsw i32 %k.030, 1<br>
>   %exitcond32 = icmp eq i32 %inc8, 50<br>
>   br i1 %exitcond32, label %for.cond10.preheader, label %for.body4<br>
><br>
><br>
> Thanks in advance,<br>
> Sara Elshobaky<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>
><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>
</div></div></blockquote></div><br></div>