<div dir="ltr">I sent my version of patch as <a href="https://reviews.llvm.org/D108581">https://reviews.llvm.org/D108581</a><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Aug 23, 2021 at 12:29 PM Rong Xu via Phabricator <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">xur added a comment.<br>
<br>
In D107034#2959896 <<a href="https://reviews.llvm.org/D107034#2959896" rel="noreferrer" target="_blank">https://reviews.llvm.org/D107034#2959896</a>>, @YolandaCY wrote:<br>
<br>
> @xur This is also reproducible using the existing test case `PGOProfile/thinlto_cspgo_gen.ll`. If evaluating the generated "`%t.2.4.opt.bc`" containing non-prevailing IRPGO flag, you will find the value is missed. (The value is still reserved in "`%t.2.3.import.bc`".)<br>
><br>
> In the LTO case, the symbol is dropped at *.preopt phase.<br>
><br>
> In summary after tracing:<br>
><br>
> 1. In LTO, the value is dropped when `addRegularLTO` as it has external linkage and non-prevailing.<br>
> 2. In ThinLTO, the value is first changed to `available_external` linkage by `thinLTOResolvePrevailingInModule` and `thinLTOResolvePrevailingGUID`. It is dropped later in the backend `GlobleOpt` pass by `deleteIfDead`.<br>
><br>
> Hence to keep the value we may need to identify the IRPGO variable in all above places, make sure it is reserved, and then drop it after instrumentation to avoid duplicate symbols in later linkage. My feeling is that using a module flag may avoid too much hassle across multiple places and more complexity to the symbol resolution stuff. (as suggested by Reid)<br>
> Agree that mixing `EnableValueProfiling` with IRPGO flag is improper as it seems Clang also may support value profiling (from comment of `shouldRecordFunctionAddr` ).<br>
> Maybe we can rename the module flag to "`CSIRPGO`"? We can also remove the flag after instrumentation as no need for later passes.<br>
<br>
OK. I now see the problem.<br>
<br>
I added IRPGOFlag was to only used to mark the profile as IR instrumentation (rather clang instrumentation). <br>
But it was later used to coordinate instrumentation pass and lowering pass.  This breaks in thin-lto and lto.<br>
<br>
IRPGOFlag now not only is used in enabling value profiling, but also in comdat renaming.<br>
<br>
I still don't want to use module flag -- using IRPGOFlag still preferred.<br>
<br>
I will fix this.<br>
<br>
<br>
Repository:<br>
  rG LLVM Github Monorepo<br>
<br>
CHANGES SINCE LAST ACTION<br>
  <a href="https://reviews.llvm.org/D107034/new/" rel="noreferrer" target="_blank">https://reviews.llvm.org/D107034/new/</a><br>
<br>
<a href="https://reviews.llvm.org/D107034" rel="noreferrer" target="_blank">https://reviews.llvm.org/D107034</a><br>
<br>
</blockquote></div>