<div style="color:#000; background-color:#fff; font-family:Courier New, courier, monaco, monospace, sans-serif;font-size:12px"><div dir="ltr" id="yui_3_16_0_1_1417176778342_6001"><span id="yui_3_16_0_1_1417176778342_6089"><font id="yui_3_16_0_1_1417176778342_6088" face="HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif">Thank you very much. -licm was what I had missing</font>.</span></div><div id="yui_3_16_0_1_1417176778342_6002"> </div><div id="yui_3_16_0_1_1417176778342_6004"><div id="yui_3_16_0_1_1417176778342_6003">- Vaivaswatha</div></div> <div class="qtdSeparateBR"><br><br></div><div style="display: block;" class="yahoo_quoted"> <div style="font-family: Courier New, courier, monaco, monospace, sans-serif; font-size: 12px;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif; font-size: 12px;"> <div dir="ltr"> <font face="Arial" size="2"> On Friday, 28 November 2014 1:59 PM, Sanjoy Das <sanjoy@playingwithpointers.com> wrote:<br> </font> </div>  <br><br> <div class="y_msg_container">What pass ordering are you using? If the "j += incr" expression incurs<br clear="none">a per-iteration load from @incr, then that can confuse SCEV.  Loop<br clear="none">invariant code motion cleans it up.<br clear="none"><br clear="none">With "opt -mem2reg -licm -S scev.ll | opt -analyze -scalar-evolution"<br clear="none">on the unoptimized IR generated by clang, I get:<br clear="none"><br clear="none">...<br clear="none">  %j.0 = phi i32 [ 0, %6 ], [ %19, %18 ]<br clear="none">  -->  {0,+,%3}<nsw><%9>                Exits: <<Unknown>><br clear="none"><div class="yqt4151194822" id="yqtfd56564"><br clear="none">On Thu, Nov 27, 2014 at 11:48 PM, Vaivaswatha N <<a shape="rect" ymailto="mailto:vaivaswatha@yahoo.co.in" href="mailto:vaivaswatha@yahoo.co.in">vaivaswatha@yahoo.co.in</a>> wrote:<br clear="none">> Hi,<br clear="none">><br clear="none">> For the program below, where "incr" and "Arr" are globals<br clear="none">> =================================<br clear="none">> int incr;<br clear="none">> float Arr[1000];<br clear="none">><br clear="none">> int foo ()<br clear="none">> {<br clear="none">>   float x = 0;<br clear="none">>   int newInc = incr+1;<br clear="none">>   for (int i = 0; i < 1000; i++) {<br clear="none">>     for (int j = 0; j < 1000; j += incr) {<br clear="none">>         x += (Arr[i] + Arr[j]);<br clear="none">>     }<br clear="none">>   }<br clear="none">>   return x;<br clear="none">> }<br clear="none">> =================================<br clear="none">><br clear="none">> The SCEV expression computed for the variable "j" is<br clear="none">>  %j.0 = phi i32 [ 0, %for.body ], [ %add8, %for.inc ]<br clear="none">>   -->  %j.0             Exits: <<Unknown>><br clear="none">> As is evident, this isn't a useful computation.<br clear="none">><br clear="none">> Whereas if I use the variable newInc to be the increment for "j", i.e., "j<br clear="none">> += newInc" in the inner loop, the computed SCEV is<br clear="none">>   %j.0 = phi i32 [ 0, %for.body ], [ %add8, %for.inc ]<br clear="none">>   -->  {0,+,(1 + %0)}<nsw><%for.cond1><br clear="none">> where %0 here is a LoadInst for "incr". In this situation, the analysis is<br clear="none">> working as expected to compute the add-recurrence for "j".<br clear="none">><br clear="none">> I would've expected a similar computation for the first case too, something<br clear="none">> like<br clear="none">> {0,+,%0}<nsw><%for.cond1><br clear="none">> Where %0 would be the LoadInst for "incr".<br clear="none">><br clear="none">> Is this a bug or is there something more involved that causes the<br clear="none">> deficiency?<br clear="none">><br clear="none">> Thanks,<br clear="none">> - Vaivaswatha</div><br clear="none">><br clear="none">> _______________________________________________<br clear="none">> LLVM Developers mailing list<br clear="none">> <a shape="rect" ymailto="mailto:LLVMdev@cs.uiuc.edu" href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a shape="rect" href="http://llvm.cs.uiuc.edu/" target="_blank">http://llvm.cs.uiuc.edu</a><br clear="none">> <a shape="rect" href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><div class="yqt4151194822" id="yqtfd35121"><br clear="none">><br clear="none"></div><br><br></div>  </div> </div>  </div> </div>