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 @@ -517,10 +517,12 @@ if (isa(Inst) || isa(Inst) || isa(Inst)) return std::error_code(); - // If a direct call/invoke instruction is inlined in profile - // (findCalleeFunctionSamples returns non-empty result), but not inlined here, - // it means that the inlined callsite has no sample, thus the call - // instruction should have 0 count. + // For non-CS profile, if a direct call/invoke instruction is inlined in + // profile (findCalleeFunctionSamples returns non-empty result), but not + // inlined here, it means that the inlined callsite has no sample, thus the + // call instruction should have 0 count. + // For CS profile, the callsite count of previously inlined callees is + // populated with the entry count of the callees. if (!ProfileIsCS) if (const auto *CB = dyn_cast(&Inst)) if (!CB->isIndirectCall() && findCalleeFunctionSamples(*CB)) @@ -545,13 +547,16 @@ if (!FS) return std::error_code(); - // If a direct call/invoke instruction is inlined in profile - // (findCalleeFunctionSamples returns non-empty result), but not inlined here, - // it means that the inlined callsite has no sample, thus the call - // instruction should have 0 count. - if (const auto *CB = dyn_cast(&Inst)) - if (!CB->isIndirectCall() && findCalleeFunctionSamples(*CB)) - return 0; + // For non-CS profile, If a direct call/invoke instruction is inlined in + // profile (findCalleeFunctionSamples returns non-empty result), but not + // inlined here, it means that the inlined callsite has no sample, thus the + // call instruction should have 0 count. + // For CS profile, the callsite count of previously inlined callees is + // populated with the entry count of the callees. + if (!ProfileIsCS) + if (const auto *CB = dyn_cast(&Inst)) + if (!CB->isIndirectCall() && findCalleeFunctionSamples(*CB)) + return 0; const ErrorOr &R = FS->findSamplesAt(Probe->Id, 0); if (R) {