<div dir="ltr">The FIXME at ScalarEvolution.cpp:4084 explains LoopUnroll's behavior on my example. I'll try to fix it. <div><br></div><div>Jingyue</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Sun, Jun 22, 2014 at 1:42 PM, Jingyue Wu <span dir="ltr"><<a href="mailto:jingyue@google.com" target="_blank">jingyue@google.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">Nice find, Mark! Thanks a lot. <div><br></div><div>I filed <a href="http://llvm.org/bugs/show_bug.cgi?id=20100" target="_blank">http://llvm.org/bugs/show_bug.cgi?id=20100</a> to track the remark issue. </div>
<span class="HOEnZb"><font color="#888888"><div><br></div>
<div>Jingyue</div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Jun 22, 2014 at 11:53 AM, Mark Heffernan <span dir="ltr"><<a href="mailto:meheff@google.com" target="_blank">meheff@google.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>On Sun, Jun 22, 2014 at 11:05 AM, Jingyue Wu <<a href="mailto:jingyue@google.com" target="_blank">jingyue@google.com</a>> wrote:<br>


> I found LLVM cannot unroll the loop in the example below, while gcc can.<br>
> Before I dig more about this issue, is this behavior as designed?<br>
<br>
</div>It doesn't unroll the loop because the trip count is not known at<br>
compile time (it could exit early because of the break), and by<br>
default loops with runtime loop counts are not unrolled.  However,<br>
even specifying -unroll-runtime still doesn't get the loop to unroll.<br>
Looking deeper it looks like runtime loop unrolling is only performed<br>
if the loop has a single exit.  See:<br>
Transforms/Util/LoopUnroll.cpp:211 and<br>
Transforms/Util/LoopUnrollRuntime.cpp:231.<br>
<br>
It'd be nice if an optimization missed remark was emitted.  Certainly<br>
a remark should be emitted in the case where you give a unroll pragma<br>
to specifically unroll the loop.  Can you file a PR about this remark<br>
issue and assign it to me?<br>
<br>
thanks,<br>
Mark<br>
<div><div><br>
><br>
> bool bar(int i);<br>
><br>
> void foo(int *a, int x, int y) {<br>
>   for (int i = 0; i < 4; ++i) {<br>
>     if (bar(i)) {<br>
>       break;<br>
>     }<br>
>     a[i] = i;<br>
>   }<br>
> }<br>
><br>
> Btw, if s/break/continue, LLVM is able to unroll it.<br>
><br>
> Thanks,<br>
> Jingyue<br>
><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>