diff --git a/llvm/lib/ProfileData/SampleProfReader.cpp b/llvm/lib/ProfileData/SampleProfReader.cpp --- a/llvm/lib/ProfileData/SampleProfReader.cpp +++ b/llvm/lib/ProfileData/SampleProfReader.cpp @@ -656,7 +656,7 @@ if (hasSecFlag(Entry, SecProfSummaryFlags::SecFlagFullContext)) FunctionSamples::ProfileIsCSFlat = ProfileIsCSFlat = true; if (hasSecFlag(Entry, SecProfSummaryFlags::SecFlagIsCSNested)) - FunctionSamples::ProfileIsCSNested = ProfileIsCSNested; + FunctionSamples::ProfileIsCSNested = ProfileIsCSNested = true; if (hasSecFlag(Entry, SecProfSummaryFlags::SecFlagFSDiscriminator)) FunctionSamples::ProfileIsFS = ProfileIsFS = true; break; diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp --- a/llvm/lib/Transforms/IPO/SampleProfile.cpp +++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp @@ -1542,6 +1542,10 @@ continue; } + // Do not merge a context that is already duplicated into the base profile. + if (FS->getContext().hasAttribute(sampleprof::ContextDuplicatedIntoBase)) + continue; + if (ProfileMergeInlinee) { // A function call can be replicated by optimizations like callsite // splitting or jump threading and the replicates end up sharing the