<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 17, 2016 at 10:06 AM, Sanjay Patel <span dir="ltr"><<a href="mailto:spatel@rotateright.com" target="_blank">spatel@rotateright.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"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Wed, Aug 17, 2016 at 10:12 AM, Xinliang David Li <span dir="ltr"><<a href="mailto:xinliangli@gmail.com" target="_blank">xinliangli@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 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"><div><div>On Wed, Aug 17, 2016 at 8:19 AM, Sanjay Patel <span dir="ltr"><<a href="mailto:spatel@rotateright.com" target="_blank">spatel@rotateright.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote"><span>On Fri, Aug 12, 2016 at 12:15 PM, Xinliang David Li via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">+dehao.<div><br></div><div>There are two potential problems:</div><div><br></div><div>1) the branch gets eliminated in the binary that is being profiled, so there is no profile data</div></div></blockquote><div><br></div></span><div>This seems like a fundamental problem for PGO. Maybe it is also responsible for this bug: <a href="https://llvm.org/bugs/show_bug.cgi?id=27359" target="_blank">https://llvm.org/bugs/show_bug<wbr>.cgi?id=27359</a> ?<br></div><div> <br></div><div>Should we limit select optimizations in IR for a PGO-training build? Or should there be a 'select smasher' pass later in the pipeline that turns selects into branches for a PGO-training build? (I don't have a good understanding of PGO, so I'm just throwing out ideas...maybe a better question is: how do other compilers handle this?)<br></div></div><br></div></div></blockquote><div><br></div></div></div><div>For instrumentation based PGO (IR-based), this is a known problem. I have a solution for it and will send out patches soon. Before that, there will be more changes in LLVM to make sure profile data associated with selectInst is well preserved.</div></div></div></div></blockquote><div><br></div></span><div>Sounds great. Let me know if I can help without getting in your way. If there's more like <a href="https://reviews.llvm.org/D23590" rel="noreferrer" target="_blank">https://reviews.llvm.org/D2359<wbr>0</a> , I can try to fix them up in parallel.<br></div></div></div></div></blockquote><div><br></div><div><br></div><div>yes there might be more missing cases -- I only did manual audition so there is no guarantee to be exhaustive. Other passes may be dropping profile data too. What we need is to  introduce a verification pass (that can be inserted after any given pass just like IR dumping) to do sanity checking: if any branch/selectInst/switchInst has dropped branch profile data (with PGO is on), emits some warning. For machine inst passes, we need something similar.  More elaborate check can also be added in the future to check the integrity of the profile data -- some pass such as jump-threading, switch lowering needs complicated update and things can go wrong there.</div><div><br></div><div>If you can help with that (verification), that will be great :)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>On a related note, I want to ask about profile-guided inlining. It does not seem to exist after <a href="https://reviews.llvm.org/D16381" target="_blank">https://reviews.llvm.org/<wbr>D16381</a> was reverted. Is there a plan to bring it back independently of the new pass manager?<br><br></div></div></div></div></blockquote><div><br></div><div>yes there is a plan. We will update the status early next month.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Profile-guided inlining was the original motivation for the test case in <a href="https://llvm.org/bugs/show_bug.cgi?id=28964" target="_blank">https://llvm.org/bugs/show_<wbr>bug.cgi?id=28964</a> . But I think we'll miss this case if we fix SimplifyCFG to produce a 'select' before fixing IR-based PGO (and making inlining work again)?<br></div><div> </div></div></div></div></blockquote><div><br></div><div>it should not. After the selectInst  is produced, the calll will be in the block outside the original if-then-else so its profile data/hotness should not be affected.</div><div><br></div><div>David</div><div> </div></div><br></div></div>