<div dir="ltr">Thanks for the comment. I spent quite a while to think, but still cannot think of an optimization that could be unblocked by speculatively hoisting an loop invariant from an unlikely executed path. Can you give some hint (or an example) on what type of optimization can benefit from this case?<div><br></div><div>Thanks,</div><div>Dehao</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 10, 2016 at 1:58 PM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:arial,helvetica,sans-serif;font-size:10pt;color:#000000"><br><br><hr><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><b>From: </b>"Xinliang David Li" <<a href="mailto:davidxl@google.com" target="_blank">davidxl@google.com</a>><br><b>To: </b>"Dehao Chen" <<a href="mailto:danielcdh@gmail.com" target="_blank">danielcdh@gmail.com</a>><br><b>Cc: </b><a href="mailto:reviews%2BD19950%2Bpublic%2B38ba22078c2035b8@reviews.llvm.org" target="_blank">reviews+D19950+public+38ba22078c2035b8@reviews.llvm.org</a>, "David Majnemer" <<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>>, "Hal Finkel" <<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>>, "Junbum Lim" <<a href="mailto:junbuml@codeaurora.org" target="_blank">junbuml@codeaurora.org</a>>, <a href="mailto:mcrosier@codeaurora.org" target="_blank">mcrosier@codeaurora.org</a>, "llvm-commits" <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>>, "amara emerson" <<a href="mailto:amara.emerson@arm.com" target="_blank">amara.emerson@arm.com</a>><br><b>Sent: </b>Tuesday, May 10, 2016 3:15:24 PM<br><b>Subject: </b>Re: [PATCH] D19950: Use frequency info to guide Loop Invariant Code Motion.<span class=""><br><br><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 10, 2016 at 1:03 PM, Dehao Chen <span dir="ltr"><<a href="mailto:danielcdh@gmail.com" target="_blank">danielcdh@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Tue, May 10, 2016 at 11:48 AM, Xinliang David Li <span dir="ltr"><<a href="mailto:davidxl@google.com" target="_blank">davidxl@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Tue, May 10, 2016 at 11:01 AM, Dehao Chen <span dir="ltr"><<a href="mailto:danielcdh@gmail.com" target="_blank">danielcdh@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">danielcdh added a comment.<br>
<span><br>
In <a href="http://reviews.llvm.org/D19950#425287" rel="noreferrer" target="_blank">http://reviews.llvm.org/D19950#425287</a>, @hfinkel wrote:<br>
<br>
> In <a href="http://reviews.llvm.org/D19950#425286" rel="noreferrer" target="_blank">http://reviews.llvm.org/D19950#425286</a>, @hfinkel wrote:<br>
><br>
> > In <a href="http://reviews.llvm.org/D19950#425285" rel="noreferrer" target="_blank">http://reviews.llvm.org/D19950#425285</a>, @davidxl wrote:<br>
> ><br>
> > > Static prediction has been conservative in estimating loop trip count -- it produces something like 30ish iterations. If the a very hot loop has a big if-then-else (or switch), it is very likely to mark many bbs' to be colder than the loop header.   Turning on this for static prediction really depends on the false rate. It seems to be this can get wrong pretty easily for very hot loops (which is also the most important thing to optimize for).<br>
> ><br>
> ><br>
> > This is a good point. There's no universal conservative choice (assuming a small trip count is conservative in some cases, and assuming a large trip count is conservative in other cases).<br>
><br>
><br>
> Would it be better (and practical) if there were some way for the BFI client to specify which kind of 'conservative' is desired?<br>
><br>
</span><span>> Also, why are we doing this instead of sinking later (in CGP or similar)? LICM can expose optimization opportunities, plus represents a code pattern the user might input manually. Sinking later seems more robust.<br>
<br>
<br>
</span>I looked at CGP pass, looks like it's handling the sinking case-by-case (e.g. there is separate routine to handle sinking of load, gep, etc. I'm afraid this would miss opportunities. Additionally, the file-level comment of CGP pass says "This works around limitations in it's basic-block-at-a-time approach. It should eventually be removed."<br></blockquote></span></div></div></div></blockquote></span></div></div></div></blockquote></div></div></div></span></blockquote>Yes, but it will be "removed" when the entire subsystem is replaced by GlobalISel, and we'll certainly need to make GlobalISel profiling-data aware, so I expect this is the right path forward regardless. I agree, however, that we want a general sinking here based on profiling data, not just the specific existing heuristics for loads, GEPs, etc.<span class=""><br><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"></blockquote><div><br></div><div><br></div></span><div>Perhaps you can do profile driven sinking CGP separately to handle manually hoisted code situation mentioned by Hal.</div></div></div></div></blockquote><div><br></div></span><div>Do you mean we still use frequency to decide whether to hoist code in LICM, additionally use frequency info to check if we want to sink instructions in CGP?</div></div></div></div></blockquote><div><br></div><div><br></div><div>yes -- that is the suggestion.</div></div></div></div></blockquote></span>I'd prefer that we try to sink late first, and only if there are use cases that we can't handle this way, we consider throttling hoisting early. If we come across such use cases, I'd like to understand them better. Hoisting can expose other optimization opportunities, and you lose those opportunities if you don't hoist in the first place.<br><br> -Hal<span class=""><br><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div><br></div><div>David</div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><font color="#888888"><div><br></div><div>Dehao</div></font></span><span><div> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><font color="#888888"><div><br></div><div>David</div></font></span><span><div> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
I'm not quite clear why it helps to move code out of loop early and later sink it inside. Could you give an example or some more context?<br>
<br>
Thanks,<br>
Dehao<br>
<br>
<br>
<a href="http://reviews.llvm.org/D19950" rel="noreferrer" target="_blank">http://reviews.llvm.org/D19950</a><br>
<br>
<br>
<br>
</blockquote></span></div><br></div></div>
</blockquote></span></div><br></div></div>
</blockquote></div><br></div></div>
</blockquote><br><br><br></span><span class="HOEnZb"><font color="#888888">-- <br><div><span name="x"></span>Hal Finkel<br>Assistant Computational Scientist<br>Leadership Computing Facility<br>Argonne National Laboratory<span name="x"></span><br></div></font></span></div></div></blockquote></div><br></div>