<p dir="ltr">Optimization passes running before LoopVectorizer should be able to combine the two statements (this should be happening in O1. Pls check)</p>
<p dir="ltr">arr[i] = a + i<br>
sum += arr[i]</p>
<p dir="ltr">to </p>
<p dir="ltr">sum += a + i</p>
<p dir="ltr">Not sure, why are you using the array there.</p>
<p dir="ltr">- Suyog</p>
<div class="gmail_quote">On 4 May 2015 23:11, "Michael Zolotukhin" <<a href="mailto:mzolotukhin@apple.com">mzolotukhin@apple.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi Yaduveer,<div><br></div><div>Vectorizer probably fails because it expects a loop in a certain form, and to convert a loop to this form one need to run some other passes first. For example, when you run “opt -O3”,  the following passes are invoked:</div><div><i><font size="1">-targetlibinfo -tti -no-aa -tbaa -scoped-noalias -assumption-cache-tracker -basicaa -ipsccp -globalopt -deadargelim -domtree -instcombine -simplifycfg -basiccg -prune-eh -inline-cost -inline -functionattrs -argpromotion -sroa -domtree -early-cse -lazy-value-info -jump-threading -correlated-propagation -simplifycfg -domtree -instcombine -tailcallelim -simplifycfg -reassociate -domtree -loops -loop-simplify -lcssa -loop-rotate -licm -loop-unswitch -instcombine -scalar-evolution -loop-simplify -lcssa -indvars -loop-idiom -loop-deletion -loop-unroll -memdep -mldst-motion -domtree -memdep -gvn -memdep -memcpyopt -sccp -domtree -bdce -instcombine -lazy-value-info -jump-threading -correlated-propagation -domtree -memdep -dse -loops -loop-simplify -lcssa -licm -adce -simplifycfg -domtree -instcombine -barrier -float2int -domtree -loops -loop-simplify -lcssa -loop-rotate -branch-prob -block-freq -scalar-evolution -loop-accesses<b> -loop-vectorize</b> -instcombine -scalar-evolution -slp-vectorizer -simplifycfg -domtree -instcombine -loops -loop-simplify -lcssa -scalar-evolution -loop-unroll -instsimplify -loop-simplify -lcssa -licm -scalar-evolution -alignment-from-assumptions -strip-dead-prototypes -globaldce -constmerge -verify</font></i></div><div><br></div><div>To get this list, you can use the following command:</div><div><font face="Menlo">llvm-as < /dev/null | opt -O3 -disable-output -debug-pass=Arguments</font></div><div><br></div><div>Now, when you get a list of passes to run before the vectorizer, you need to get ‘unoptimized’ IR and run the passes on it - that should give you IR just before the vectorizer.</div><div><br></div><div>To get the unoptimized IR, you could use</div><div><font face="Menlo">clang -O3 -mllvm -disable-llvm-optzns -emit-llvm your_source.c -S -o unoptimized_ir.ll</font></div><div>(Please note that we use “-O3 -mllvm -disable-llvm-optzns”, not just “-O0” - that allows us to run analysis passes, but not transformations)</div><div><br></div><div>Now you run ‘opt’ with passes preceding the vectorizer to get IR before vectorization:</div><div><font face="Menlo">opt -targetlibinfo -tti -no-aa -tbaa …… -scalar-evolution -loop-accesses unoptimized_ir.ll -S -o ir_before_loop_vectorize.ll</font></div><div>(you might want to remove verifier passes from the list)</div><div><br></div><div>And after this you are ready to run the vectorizer:</div><div><font face="Menlo">opt -loop-vectorize ir_before_loop_vectorize.ll -S -o ir_after_loop_vectorize.ll</font></div><div><br></div><div>Hopefully, that’ll resolve the issues you are facing.</div><div><br></div><div>Thanks,</div><div>Michael</div><div><br></div><div><br></div><div><div><blockquote type="cite"><div>On May 3, 2015, at 9:18 AM, yaduveer singh <<a href="mailto:yaduveer99@gmail.com" target="_blank">yaduveer99@gmail.com</a>> wrote:</div><br><div><div dir="ltr">Hi Michael,<div><br></div><div>I tried running my sample C program using "LoopVectorizePass" but I was not able to get the output as I was expecting. Every time I got the message </div><div>"LV: Not vectorizing: Cannot prove legality."</div><div><br></div><div>Following is the scenario.</div><div><br></div><div>c-code</div><div><br></div><div><div>#include <stdio.h></div><div>int main()</div><div>{</div><div><span style="white-space:pre-wrap">      </span>int i;</div><div><span style="white-space:pre-wrap">   </span>int a=2;</div><div><span style="white-space:pre-wrap"> </span>int sum=0;</div><div><span style="white-space:pre-wrap">       </span>int arr[400];</div><div><br></div><div><span style="white-space:pre-wrap">   </span>for(i=0;i<400;i=i+1)</div><div><span style="white-space:pre-wrap">  </span>{</div><div><span style="white-space:pre-wrap">                </span>arr[i]=a+i;</div><div><span style="white-space:pre-wrap">              </span>sum+=arr[i];       </div><div><span style="white-space:pre-wrap">  </span>}</div><div><span style="white-space:pre-wrap">        </span>printf("Everything is Done for 1d\n");</div><div><span style="white-space:pre-wrap"> </span>return 0;</div><div>}</div></div><div><br></div><div>following are my command:</div><div><br></div><div><div>yaduveer@yaduveer-Inspiron-3542:~/RP$ clang -S -emit-llvm loop1d.c</div><div>yaduveer@yaduveer-Inspiron-3542:~/RP$ clang -c -emit-llvm loop1d.c</div><div>yaduveer@yaduveer-Inspiron-3542:~/RP$ opt -loop-vectorize -force-vector-width=4 -mem2reg -loop-rotate -indvars -debug -stats loop1d.ll | llvm-dis -o loop1dv1.ll</div></div><div><br></div><div>we found the following message on the terminal:(Attached is the details found on terminal and the 2 .ll files)</div><div><br></div><div><div>LV: Checking a loop in "main" from loop1d.ll</div><div>LV: Loop hints: force=? width=4 unroll=0</div><div>LV: Not vectorizing: Cannot prove legality.</div></div><div><br></div><div>so can you please let me know if I am following correct steps.</div><div>If not, please guide me.</div><div><br></div><div><br></div><div>Thanks in advance.</div><div><br></div><div class="gmail_extra"><br clear="all"><div><div><div dir="ltr">Regards,<div>Yaduveer</div></div></div></div>
<br><div class="gmail_quote">On Sun, May 3, 2015 at 12:32 AM, yaduveer singh <span dir="ltr"><<a href="mailto:yaduveer99@gmail.com" target="_blank">yaduveer99@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Michael,<div><br></div><div>Thank you very much! </div><div>I will try this.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Regards,</div><div class="gmail_extra">Yaduveer</div><div><div><div class="gmail_extra"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, May 3, 2015 at 12:11 AM, Michael Zolotukhin <span dir="ltr"><<a href="mailto:mzolotukhin@apple.com" target="_blank">mzolotukhin@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 Yaduveer,<br>
<br>
As far as I remember, unroller in LoopVectorizer pass does what you want to achieve (look for a message "LV: Trying to at least unroll the loops.” to locate this in the code).<br>
<br>
Michael<br>
<div><div><br>
> On May 2, 2015, at 9:00 AM, yaduveer singh <<a href="mailto:yaduveer99@gmail.com" target="_blank">yaduveer99@gmail.com</a>> wrote:<br>
><br>
> Hi Zhoulai,<br>
><br>
> I am trying to modify "LoopUnrollPass" in llvm which produces multiple<br>
> copies of loop equal to the loop unroll factor.Currently, using multicore<br>
> architecture, say 3 for example and the execution goes like:<br>
><br>
> for 3 cores if there are 9 iterations of loop<br>
> core          instruction<br>
> 1                   0,3,6<br>
> 2                    1,4,7<br>
> 3                    2,5,8<br>
><br>
> But I want to to modify such that it can execute in following way:<br>
><br>
> core          instruction<br>
> 1                   0,1,2<br>
> 2                   3,4,5<br>
> 3                   6,7,8<br>
><br>
> I am not able to get where to modify for this. I tried creating a sample<br>
> pass using original LoopUnrollPass code and run "make", I received<br>
> following error:<br>
><br>
> loopunrollp.cpp:210:1: error: ‘void<br>
> llvm::initializeLoopUnrollpPass(llvm::PassRegistry&)’ should have been<br>
> declared inside ‘llvm’<br>
> /bin/rm: cannot remove<br>
> `/home/yaduveer/RP/LLVM/llvm/lib/Transforms/loopunrollp/Debug+Asserts/loopunrollp.d.tmp':<br>
> No such file or directory<br>
><br>
><br>
> Please help<br>
><br>
> Thanks,<br>
> Yaduveer<br>
><br>
</div></div>> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">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>
</blockquote></div><br></div></div></div></div>
</blockquote></div><br></div></div>
<span><messageOnCommandLine.txt></span><span><loop1d.c></span><span><loop1d.ll></span><span><loop1dv1.ll></span></div></blockquote></div><br></div></div><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></blockquote></div>