Index: lib/IR/Function.cpp =================================================================== --- lib/IR/Function.cpp +++ lib/IR/Function.cpp @@ -1333,7 +1333,9 @@ if (MDS->getString().equals("function_entry_count")) { ConstantInt *CI = mdconst::extract(MD->getOperand(1)); uint64_t Count = CI->getValue().getZExtValue(); - if (Count == 0) + // A value of -1 is used for SamplePGO when there were no samples. + // Treat this the same as unknown. + if (Count == (uint64_t)-1) return None; return Count; } Index: lib/Transforms/IPO/SampleProfile.cpp =================================================================== --- lib/Transforms/IPO/SampleProfile.cpp +++ lib/Transforms/IPO/SampleProfile.cpp @@ -1583,7 +1583,7 @@ } bool SampleProfileLoader::runOnFunction(Function &F, ModuleAnalysisManager *AM) { - F.setEntryCount(0); + F.setEntryCount(-1); std::unique_ptr OwnedORE; if (AM) { auto &FAM = Index: test/Transforms/SampleProfile/entry_counts.ll =================================================================== --- test/Transforms/SampleProfile/entry_counts.ll +++ test/Transforms/SampleProfile/entry_counts.ll @@ -9,8 +9,8 @@ ret void, !dbg !9 } -; This function does not have profile, check if function_entry_count is 0 -; CHECK: {{.*}} = !{!"function_entry_count", i64 0} +; This function does not have profile, check if function_entry_count is -1 +; CHECK: {{.*}} = !{!"function_entry_count", i64 -1} define void @no_profile() { entry: ret void