diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -4148,7 +4148,14 @@ // For local linkage, we also emit the original name separately // immediately after the record. auto MaybeEmitOriginalName = [&](GlobalValueSummary &S) { - if (!GlobalValue::isLocalLinkage(S.linkage())) + // We don't need to emit the original name if we are writing the index for + // distributed backends (in which case ModuleToSummariesForIndex is + // non-null). The original name is only needed during the thin link, since + // for SamplePGO the indirect call targets for local functions have + // have the original name annotated in profile. + // Continue to emit it when writing out the entire combined index, which is + // used in testing the thin link via llvm-lto. + if (ModuleToSummariesForIndex || !GlobalValue::isLocalLinkage(S.linkage())) return; NameVals.push_back(S.getOriginalName()); Stream.EmitRecord(bitc::FS_COMBINED_ORIGINAL_NAME, NameVals); diff --git a/llvm/test/ThinLTO/X86/distributed_indexes.ll b/llvm/test/ThinLTO/X86/distributed_indexes.ll --- a/llvm/test/ThinLTO/X86/distributed_indexes.ll +++ b/llvm/test/ThinLTO/X86/distributed_indexes.ll @@ -20,10 +20,12 @@ ; BACKEND1-DAG: +; BACKEND1-DAG: ; BACKEND1-NEXT: +; BACKEND2-NEXT: ; BACKEND2-NEXT: