<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 2, 2016 at 12:24 AM, Sean Silva <span dir="ltr"><<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@gmail.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, May 25, 2016 at 9:22 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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">It sounds to me we are likely to converge on the following:<div><br></div><div>1) Making IR/llvm based PGO the default;</div><div>2) Enhance -fcoverage-mapping such that it automatically turns on FE based instrumentation</div><div>3) if -fcoverage-mapping is used together with -fprofile-instr-generate, -fcoverage-mapping serves as a switch to turn on FE based instrumetnation</div><div><br></div><div>All the above are transparent to users.</div><div><br></div><div>The following are for advanced usage:</div><div><br></div><div>4) have a new option to explicitly switch instrumentation flavor to be FE based</div><div>5) have a new option to turn off part of pre-instrumentation cleanup/simplification passes for users who want very stable profile for stable library sources *</div><div><br></div><div>* 4 and 5 serves the same purpose so 5 may not be necessary.</div></div></blockquote><div><br></div></span><div>One question for your David, related to merging indexed profiles. The requirement that indexed profiles from different compiler versions can be merged (with the intended result) implies that the CFG hash for a given function must be the same (this is the change that actually breaks merging IRPGO vs FEPGO). But the same issue in principle applies to IRPGO across compiler versions. How likely do you think it will be that this hash may change? I can think of two sources:</div><div>a) we decide to walk the CFG differently for computing the hash or decide to use a different hash function etc.</div><div>b) pre-instrumentation passes change across compiler versions (e.g. inliner makes different decisions in a newer compiler version)</div><div><br></div><div>`b)` definitely seems like it will be a problem. What do you think about a)?</div></div></div></div></blockquote><div><br></div><div>Strictly speaking, the requirement is just that index format change is backward compatible -- this includes changes of PGO name encoding scheme. For content function hashing, unless we systematically change the hash algorithm which will require a version bump, local compiler changes (such as bug fixes) that lead to hashing to be different for individual functions should not be considered breaking compatibility. This can happen for both IR and FE instrumentation. </div><div><br></div><div>The above should apply to b) as well. It is true that b) is more sensitive to compiler version changes in a way that more individual functions' profile may get invalidated due to version change, but I think this is by design -- keeping profile fully compatible across compiler versions is not the major intended use cases. However if cfg traverse order changes, I think a version bump is needed. This however should be fairly rarely.</div><div><br></div><div>David</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"><span class="HOEnZb"><font color="#888888"><div></div><div>-- Sean Silva</div></font></span><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div>thanks,</div><div><br></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 24, 2016 at 5:21 PM, Sean Silva <span dir="ltr"><<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Tue, May 24, 2016 at 3:41 PM, Vedant Kumar <span dir="ltr"><<a href="mailto:vsk@apple.com" target="_blank">vsk@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><span><br>
> On May 23, 2016, at 8:56 PM, Xinliang David Li <<a href="mailto:davidxl@google.com" target="_blank">davidxl@google.com</a>> wrote:<br>
><br>
> On Mon, May 23, 2016 at 8:23 PM, Sean Silva <<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@gmail.com</a>> wrote:<br>
> Jake and I have been integrating IRPGO on PS4, and we've identified 3 remaining work items.<br>
><br>
> Sean, thanks for the write up. It matches very well with what we think as well.<br>
<br>
</span>+ 1<br>
<span><br>
<br>
> - Driver changes<br>
><br>
> We'd like to make IRPGO the default on PS4. We also think that it would be beneficial to make IRPGO the default PGO on all platforms (coverage would continue to use FE instr as it does currently, of course). In previous conversations (e.g. <a href="http://reviews.llvm.org/D15829" rel="noreferrer" target="_blank">http://reviews.llvm.org/D15829</a>) it has come up that Apple have requirements that would prevent them from moving to IRPGO as the default PGO, at least without a deprecation period of one or two releases.<br>
<br>
</span>Sean pointed out the problematic scenario in D15829 (in plan "C"):<br>
<br>
```<br>
All existing user workflows continue to work, except for workflows that attempt to llvm-profdata merge some old frontend profile data (e.g. they have checked-in to version control and represents some special workload) with the profile data from new binaries.<br>
```<br>
<br>
We can address this issue by (1) making sure llvm-profdata emits a helpful warning when merging an FE-based profile with an IR-based one, and (2) keeping an option to use FE instrumentation for PGO. Having (2) helps people who can't (or don't want) to switch to IR PGO.<br>
<span><br>
<br>
> I'd like to get consensus on a path forward.<br>
> As a point of discussion, how about we make IRPGO the default on all platforms except Apple platforms.<br>
<br>
</span>I'd really rather not introduce this inconsistency. I'm worried that it might lead to Darwin becoming a second-tier platform for PGO.<br>
<br>
Fred (CC'd) is following up with some of our internal users to check if we can change the default behavior of -fprofile-instr-generate. He should be able to chime in on this soon.<br></blockquote><div><br></div></span><div>Great!</div><span><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<br>
At its core I don't think -fprofile-instr-generate *implies* FE-based instrumentation. So, I'd like to see the driver do this (on all platforms):<br>
<br>
* -fprofile-instr-generate: IR instrumentation<br>
* -fprofile-instr-generate=IR: IR instrumentation<br>
* -fprofile-instr-generate=FE: FE instrumentation<br>
* -fprofile-instr-generate -fcoverage-mapping: FE + coverage instrumentation<br>
<br>
It's a bit ugly because the meaning of -fprofile-instr-generate becomes context-sensitive. But, (1) it doesn't break existing common workflows and (2) it makes it easier to ship IRPGO. The big caveat here is that we'll need to wait a bit and see if our internal users are OK with this.<br></blockquote><div><br></div></span><div>Is there a reason to even have the possibility for FEPGO in the long run? From what I can tell, at most we would add a <span style="font-size:12.8px">-fuse-the-old-pgo-because-i-</span><span style="font-size:12.8px">want-to-merge-with-old-</span><span style="font-size:12.8px">profiles option to hold people over until they can regenerate their profiles with the current compiler. We can add a flag to control what pre-instrumentation is done to retain the source-level robustness of FEPGO (e.g. -fpgo-no-simplify-before-instrumenting or something).</span></div><span><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<br>
One alternative is to introduce a separate driver flag for IRPGO. This might not work well for Sony's existing users. I'd be interested in any feedback about this approach.<br></blockquote><div><br></div></span><div>Personally, I would prefer to maintaining command line compatibility for PGO in Clang (i.e. users don't have to modify their build systems).</div><span><font color="#888888"><div><br></div><div><br></div><div>-- Sean Silva</div></font></span><div><div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<span><br>
<br>
> I really don't like fragmenting things like this (e.g. if a third-party tests "clang's" PGO they will get something different depending on the platform), but I don't see another way given Apple's constraints.<br>
><br>
> I'd like to see IRPGO to be the default as well, but the first thing we need is a driver level option to make the switch (prof-gen) -- currently we rely on -Xclang option to switch between two modes, which is less than ideal.<br>
><br>
> If the concern from Apple is that the old profile still need to work, then this is problem already solved. The reason is that -fprofile-instr-use can automatically detect the type of the profile and switch the mode.<br>
<br>
</span>It's not just that. As Sean pointed out, we're concerned about old profiles inter-operating poorly with new ones.<br>
<br>
thanks,<br>
vedant<br>
<br>
<br>
> - Pre-instrumentation passes<br>
><br>
> Pre-instrumentation optimization has been critical for reducing the overhead of PGO for the PS4 games we tested (as expected). However, in our measurements (and we are glad to provide more info) the main benefit was inlining (also as expected). A simple pass of inlining at threshold 100 appeared to give all the benefits. Even inlining at threshold 0 gave almost all the benefits. For example, the passes initially proposed in <a href="http://reviews.llvm.org/D15828did" rel="noreferrer" target="_blank">http://reviews.llvm.org/D15828did</a> not improve over just inlining with threshold 100.<br>
<div><div>><br>
> (due to PR27299 we also need to add simplifycfg after inlining to clean up, but this doesn't affect the instrumentation overhead in our measurements)<br>
><br>
> Bottom line: for our use cases, inlining does all the work, but we're not opposed to having more passes, which might be beneficial for non-game workloads (which is most code).<br>
><br>
><br>
><br>
> Yes, Rong is re-collecting performance data before submitting the patch.<br>
><br>
> - Warnings<br>
><br>
> We identified 3 classes of issues which manifest as spammy warnings when applying profile data with IRPGO (these affect FEPGO also I believe, but we looked in depth at IRPGO):<br>
><br>
> 1. The main concerning one is that getPGOFuncName mangles the filename into the counter name. This causes us to get instrprof_error::unknown_function when the pgo-use build is done in a different build directory from the training build (which is a reasonable thing to support). In this situation, PGO data is useless for all `static` functions (and as a byproduct results in a huge volume of warnings).<br>
><br>
> This can be enhanced with an user option to override the behavior. Can you help filing a tracking bug?<br>
><br>
><br>
> 2. In different TU's, pre-instr inlining might make different inlining decisions (for example, different functions may be available for inlining), causing hash mismatch errors (instrprof_error::hash_mismatch). In building a large game, we only saw 8 instance of this, so it is not as severe as 1, but would be good to fix.<br>
><br>
><br>
> Rong has a patch addressing that -- will submit after cleanup pass change is done.<br>
><br>
><br>
> 3. A .cpp file may be compiled and put into an archive, but then not selected by the linker and will therefore not result in a counter in the profraw. When compiling this file with pgo-use, instrprof_error::unknown_function will result and a warning will be emitted.<br>
><br>
> yes -- this is a common problem to other compilers as well.<br>
><br>
><br>
><br>
> Case 1 can be fixed using a function hash or other unique identifier instead of a file path. David, in D20195 you mentioned that Rong was working on a patch that would fix 2; we are looking forward to that.<br>
><br>
><br>
> Right.<br>
><br>
> For 3, I unfortunately do not know of any solution. I don't think there is a way for us to make this warning reliable in the face of this circumstance. So my conclusion is that instrprof_error::unknown_function at least must be defaulted to off unfortunately.<br>
><br>
> yes, this can be annoying. If the warnings can be buffered, then the compiler can check if this is due to missing profile for the whole file and can reduce the warnings into one single warning (source file has no profile data). Making it off by default sounds fine to me too if it is too noisy.<br>
><br>
> thanks,<br>
><br>
> David<br>
><br>
><br>
> -- Sean Silva<br>
<br>
</div></div></blockquote></div></div></div><br></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div></div></div><br></div></div>
</blockquote></div><br></div></div>