Currently IndirectCallPromotion simply strip everything after the first "." in LTO mode, in order to match the symbol name and the name with ".llvm." suffix in the value profile. However, if -funique-internal-linkage-names and thinlto are both enabled, the name may have both ".uniq." suffix and ".llvm." suffix (".uniq." will only exist before ".llvm."), and the current mechanism will strip them both, which will block indirect call promotion in both InstrPGO and SamplePGO modes. The patch fixes the problem.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/ProfileData/InstrProf.cpp | ||
---|---|---|
355–356 | Not too familiar with this code, is there a chance you could have a different suffix other than "__uniq" before the .llvm suffix like say "constprop" ? In this case that suffix would be retained by this change which would be different from the original behavior. |
llvm/lib/ProfileData/InstrProf.cpp | ||
---|---|---|
355–356 | getCanonicalFnName has other known suffixes, do we need to consider these as well? |
llvm/lib/ProfileData/InstrProf.cpp | ||
---|---|---|
355–356 | '.constprop.' and '.part.' suffix handled in getCanonicalFnName were used by GCC but I don't find them in llvm. I am not aware of function suffix other than ".llvm." and ".uniq." used by llvm, but you and Sri are right it is good to keep the original behavior as much as possible. I will change it to only keep ".uniq.". |
llvm/lib/ProfileData/InstrProf.cpp | ||
---|---|---|
355–356 | Wondering if it makes sense to use getCanonicalFnName here, maybe with an argument indicating only ".uniq" should be kept. |
llvm/lib/ProfileData/InstrProf.cpp | ||
---|---|---|
355–356 | Here instrPGO is also impacted. To make instrPGO and samplePGO share getCanonicalFnName means a larger churn. I will put an argument there to make it clear. |
FWIW, I'm seeing errors like "Malformed instrumentation profile data" when building code for a i686-w64-mingw32 target after this commit. I've yet to reduce the actual trigger for it, but I thought I'd let you know...
Thanks Martin for reporting the error. I think the error is thrown in the call of addFuncName(OtherFuncName) here:
https://github.com/llvm/llvm-project/blob/b552adf8b388a4fbdaa6fb46bdedc83fc738fc2b/llvm/lib/ProfileData/InstrProf.cpp#L376
Could you help to get the "PGOFuncName" string before addFuncName throws the error? Then we can know what is wrong.
Ok, sure. Here's a full reproducer:
$ cat ../repro.c static void func(void) { } void (*funcptr)(void) = func; $ clang -target x86_64-linux-gnu -c ../repro.c -O2 PGOFuncName "../repro.c:func" OtherFuncName "" Program aborted due to an unhandled Error: Malformed instrumentation profile data
Thanks Martin. The problem is fixed and patch recommitted at https://github.com/llvm/llvm-project/commit/ef9d7db72362b2df1237a87d5dc7dad6b0105df6
Not too familiar with this code, is there a chance you could have a different suffix other than "__uniq" before the .llvm suffix like say "constprop" ? In this case that suffix would be retained by this change which would be different from the original behavior.