<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 3, 2015 at 5:46 PM, Justin Bogner <span dir="ltr"><<a href="mailto:mail@justinbogner.com" target="_blank">mail@justinbogner.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">Alexey Samsonov <<a href="mailto:vonosmas@gmail.com">vonosmas@gmail.com</a>> writes:<br>
> Hi Justin,<br>
><br>
> On Fri, Apr 3, 2015 at 5:05 PM, Justin Bogner <<a href="mailto:mail@justinbogner.com">mail@justinbogner.com</a>> wrote:<br>
><br>
>     Alexey Samsonov <<a href="mailto:vonosmas@gmail.com">vonosmas@gmail.com</a>> writes:<br>
>     > Author: samsonov<br>
>     > Date: Wed Apr  1 20:30:10 2015<br>
>     > New Revision: 233881<br>
>     ><br>
>     > URL: <a href="http://llvm.org/viewvc/llvm-project?rev=233881&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=233881&view=rev</a><br>
>     > Log:<br>
>     > Fix a bug indicated by -fsanitize=shift-exponent.<br>
><br>
>     I noticed a significant performance regression Benchmarks/Shootout/sieve<br>
>     after this change. I suspect this isn't quite the right fix for the<br>
>     undefined behaviour.<br>
><br>
>     You can see the performance jump in lnt here:<br>
><br>
>         <a href="http://llvm-lnt.herokuapp.com/db_default/v4/nts/graph?plot.0=3.794.3&" target="_blank">http://llvm-lnt.herokuapp.com/db_default/v4/nts/graph?plot.0=3.794.3&</a><br>
>     highlight_run=9976<br>
><br>
>     There's a big regression between r233879 and r233882. This is the only<br>
>     interesting change in that range.<br>
><br>
>     > Modified:<br>
>     >     llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp<br>
>     ><br>
>     > Modified: llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp<br>
>     > URL:<br>
>     > <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/</a><br>
>     LoopUnrollRuntime.cpp?rev=233881&r1=233880&r2=233881&view=diff<br>
>     > ========================================================================<br>
>     ======<br>
>     > --- llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp (original)<br>
>     > +++ llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp Wed Apr  1<br>
>     20:30:10 2015<br>
>     > @@ -320,7 +320,7 @@ bool llvm::UnrollRuntimeLoopProlog(Loop<br>
>     >    // This constraint lets us deal with an overflowing trip count<br>
>     easily; see the<br>
>     >    // comment on ModVal below.  This check is equivalent to `Log2(Count)<br>
>     <<br>
>     >    // BEWidth`.<br>
>     > -  if (static_cast<uint64_t>(Count) > (1ULL << BEWidth))<br>
>     > +  if (BEWidth < 64 && static_cast<uint64_t>(Count) > (1ULL << BEWidth))<br>
><br>
>     To match what the comment says we're doing, I guess we want:<br>
><br>
>       if (BEWidth >= 64 || static_cast<uint64_t>(Count) > (1ULL << BEWidth))<br>
><br>
>     since Log2(Count) is guaranteed to be less than 64.<br>
><br>
> ... but if BEWidth is 64, than Count can never be greater than 1ULL <<<br>
> BEWidth, and we should *not* return false.<br>
> Note that the comment doesn't match the current code.<br>
<br>
</div></div>Oh, the code says greater, where the comment says less. Strange. I<br>
certainly meant to use less in my suggested change, but I misread and<br>
thought the current code was using less as well.<br>
<br>
In any case, it seems whatever we ended up doing when we hit the<br>
undefined behaviour generated faster code for the benchmark ;)<br></blockquote><div><br></div><div>Heh, if BEWidth is 64 than (1ULL << BEWidth) will overflow and will likely be just 1</div><div>(at least that's how gcc and clang behave on my machine), and we will break from the</div><div>function and return false, instead of doing the actual unrolling below.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
><br>
>     >      return false;<br>
>     ><br>
>     >    // If this loop is nested, then the loop unroller changes the code in<br>
>     ><br>
>     ><br>
>     > _______________________________________________<br>
>     > llvm-commits mailing list<br>
>     > <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
>     > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
><br>
> --<br>
> Alexey Samsonov<br>
> <a href="mailto:vonosmas@gmail.com">vonosmas@gmail.com</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Alexey Samsonov<br><a href="mailto:vonosmas@gmail.com" target="_blank">vonosmas@gmail.com</a></div></div>
</div></div>