[PATCH] D41307: [PGO] Fix handling of cold entry count for instrumented PGO

Teresa Johnson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 15 13:09:35 PST 2017


tejohnson created this revision.
tejohnson added reviewers: danielcdh, davidxl.

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.


https://reviews.llvm.org/D41307

Files:
  lib/IR/Function.cpp
  lib/Transforms/IPO/SampleProfile.cpp
  test/Transforms/SampleProfile/entry_counts.ll


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
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<OptimizationRemarkEmitter> OwnedORE;
   if (AM) {
     auto &FAM =
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<ConstantInt>(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;
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41307.127184.patch
Type: text/x-patch
Size: 1605 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171215/e13e3fc9/attachment.bin>


More information about the llvm-commits mailing list