[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
Mon Dec 18 12:03:42 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL321018: [PGO] Fix handling of cold entry count for instrumented PGO (authored by tejohnson, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D41307

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


Index: llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp
===================================================================
--- llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp
+++ llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp
@@ -1583,7 +1583,10 @@
 }
 
 bool SampleProfileLoader::runOnFunction(Function &F, ModuleAnalysisManager *AM) {
-  F.setEntryCount(0);
+  // Initialize the entry count to -1, which will be treated conservatively
+  // by getEntryCount as the same as unknown (None). If we have samples this
+  // will be overwritten in emitAnnotations.
+  F.setEntryCount(-1);
   std::unique_ptr<OptimizationRemarkEmitter> OwnedORE;
   if (AM) {
     auto &FAM =
Index: llvm/trunk/lib/IR/Function.cpp
===================================================================
--- llvm/trunk/lib/IR/Function.cpp
+++ llvm/trunk/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;
       }
Index: llvm/trunk/test/Transforms/SampleProfile/entry_counts.ll
===================================================================
--- llvm/trunk/test/Transforms/SampleProfile/entry_counts.ll
+++ llvm/trunk/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


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


More information about the llvm-commits mailing list