Skip to content

Commit 915897e

Browse files
committedDec 18, 2017
[PGO] Fix handling of cold entry count for instrumented PGO
Summary: In r277849, getEntryCount was changed to return None when the entry count was 0, specifically for SamplePGO where it means no samples were recorded. However, for instrumentation PGO a 0 entry count should be returned directly, since it does mean that the function was completely cold. Otherwise we end up treating these functions conservatively in isFunctionEntryCold() and isColdBB(). Instead, for SamplePGO use -1 when there are no samples, and change getEntryCount to return None when the value is -1. Reviewers: danielcdh, davidxl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D41307 llvm-svn: 321018
1 parent ec76d9c commit 915897e

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed
 

‎llvm/lib/IR/Function.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,9 @@ Optional<uint64_t> Function::getEntryCount() const {
13331333
if (MDS->getString().equals("function_entry_count")) {
13341334
ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(1));
13351335
uint64_t Count = CI->getValue().getZExtValue();
1336-
if (Count == 0)
1336+
// A value of -1 is used for SamplePGO when there were no samples.
1337+
// Treat this the same as unknown.
1338+
if (Count == (uint64_t)-1)
13371339
return None;
13381340
return Count;
13391341
}

‎llvm/lib/Transforms/IPO/SampleProfile.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1583,7 +1583,10 @@ bool SampleProfileLoaderLegacyPass::runOnModule(Module &M) {
15831583
}
15841584

15851585
bool SampleProfileLoader::runOnFunction(Function &F, ModuleAnalysisManager *AM) {
1586-
F.setEntryCount(0);
1586+
// Initialize the entry count to -1, which will be treated conservatively
1587+
// by getEntryCount as the same as unknown (None). If we have samples this
1588+
// will be overwritten in emitAnnotations.
1589+
F.setEntryCount(-1);
15871590
std::unique_ptr<OptimizationRemarkEmitter> OwnedORE;
15881591
if (AM) {
15891592
auto &FAM =

‎llvm/test/Transforms/SampleProfile/entry_counts.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ entry:
99
ret void, !dbg !9
1010
}
1111

12-
; This function does not have profile, check if function_entry_count is 0
13-
; CHECK: {{.*}} = !{!"function_entry_count", i64 0}
12+
; This function does not have profile, check if function_entry_count is -1
13+
; CHECK: {{.*}} = !{!"function_entry_count", i64 -1}
1414
define void @no_profile() {
1515
entry:
1616
ret void

0 commit comments

Comments
 (0)