[llvm] r321018 - [PGO] Fix handling of cold entry count for instrumented PGO

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 18 12:02:44 PST 2017


Author: tejohnson
Date: Mon Dec 18 12:02:43 2017
New Revision: 321018

URL: http://llvm.org/viewvc/llvm-project?rev=321018&view=rev
Log:
[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

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

Modified: llvm/trunk/lib/IR/Function.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Function.cpp?rev=321018&r1=321017&r2=321018&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Function.cpp (original)
+++ llvm/trunk/lib/IR/Function.cpp Mon Dec 18 12:02:43 2017
@@ -1333,7 +1333,9 @@ Optional<uint64_t> Function::getEntryCou
       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;
       }

Modified: llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp?rev=321018&r1=321017&r2=321018&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp Mon Dec 18 12:02:43 2017
@@ -1583,7 +1583,10 @@ bool SampleProfileLoaderLegacyPass::runO
 }
 
 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 =

Modified: llvm/trunk/test/Transforms/SampleProfile/entry_counts.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SampleProfile/entry_counts.ll?rev=321018&r1=321017&r2=321018&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SampleProfile/entry_counts.ll (original)
+++ llvm/trunk/test/Transforms/SampleProfile/entry_counts.ll Mon Dec 18 12:02:43 2017
@@ -9,8 +9,8 @@ entry:
   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




More information about the llvm-commits mailing list