<div dir="ltr"><div><div>Still, there a question:<br></div><div>1) does loop analysis always find only outermost loop? I can't make it finding all innermost ones (LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo()). With other means it is possible,but not so convenient;<br></div><div>2) is the trip count value determined only when there is one exit block (I have seen such assert in code, but maybe there are other functions, that can overcome this difficulty)? In this example I have not fully optimized version but still I can't be sure that this will not happen even after full optimization pass:<br><br>define i32 @main() #0 {<br>  br label %1<br><br>; <label>:1                                       ; preds = %0, %4<br>  %i.03 = phi i32 [ 0, %0 ], [ %5, %4 ]<br>  %a.02 = phi i32 [ 0, %0 ], [ %2, %4 ]<br>  %2 = add i32 %a.02, %i.03<br>  %3 = icmp sgt i32 %i.03, 7<br>  br i1 %3, label %.loopexit, label %4<br><br>; <label>:4                                       ; preds = %1<br>  %5 = add nsw i32 %i.03, 1<br>  %6 = icmp ne i32 %5, 10<br>  br i1 %6, label %1, label %.loopexit<br><br>.loopexit:                                        ; preds = %4, %1<br>  %a.1 = phi i32 [ %2, %1 ], [ %2, %4 ]<br>  ret i32 %a.1<br>}<br><br></div><div>the c code<br></div><div><br>    unsigned a = 0;<br>    for (int i = 0; i != 10; i++) {<br>      a+=i;<br>      if (i > 7)<br>        break;<br>    }<br>    return a;<br><br></div><div>of course if I will apply instcombine with indvars passes, then it will look more logical, but anyway the loop trip count here is 7 , not 10, not 0 ( the max number we can enter the loop). But it can't be determined with the help of information from ScalarEvolution.<br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-07-26 9:24 GMT+02:00 Anastasiya Ruzhanskaya <span dir="ltr"><<a href="mailto:anastasiya.ruzhanskaya@frtk.ru" target="_blank">anastasiya.ruzhanskaya@frtk.ru</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Great, thanks a lot!<br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">2017-07-25 23:48 GMT+02:00 Sanjoy Das <span dir="ltr"><<a href="mailto:sanjoy@google.com" target="_blank">sanjoy@google.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Anastasiya,<br>
<br>
If it fits you use case, you can consider walking the loop header and<br>
calling getSCEV() on all of the PHI nodes in the header.  This will<br>
give you a SCEV* which should be easier to analyze than manually<br>
inspecting PHI cycles.<br>
<br>
Thanks!<br>
<span class="m_4764275048580256378HOEnZb"><font color="#888888">-- Sanjoy<br>
</font></span><div class="m_4764275048580256378HOEnZb"><div class="m_4764275048580256378h5"><br>
<br>
On Tue, Jul 25, 2017 at 11:42 AM, Michael Kruse via llvm-dev<br>
<<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
> 2017-07-25 19:32 GMT+02:00 Anastasiya Ruzhanskaya<br>
> <<a href="mailto:anastasiya.ruzhanskaya@frtk.ru" target="_blank">anastasiya.ruzhanskaya@frtk.r<wbr>u</a>>:<br>
>> I call this function and it returns only "i" in my example.  Are there any<br>
>> ways to return "j" also?<br>
><br>
> That would contradict it being the /canonical/ induction variable, wouldn't it?<br>
><br>
> If you look into the imlplementation of<br>
> getCanonicalInductionVariable(<wbr>), it just walks the IR instructions and<br>
> checks some conditions. You can have your own implementation that,<br>
> instead of returning the first matching PHI, return all matching PHIs.<br>
> SimplifyIndVar won't try to canonicalize, though.<br>
><br>
> Michael<br>
</div></div><div class="m_4764275048580256378HOEnZb"><div class="m_4764275048580256378h5">> ______________________________<wbr>_________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>