]> granicus.if.org Git - llvm/commitdiff
Handle early inline for hot callsites that reside in the same basic block.
authorDehao Chen <dehao@google.com>
Mon, 19 Sep 2016 18:38:14 +0000 (18:38 +0000)
committerDehao Chen <dehao@google.com>
Mon, 19 Sep 2016 18:38:14 +0000 (18:38 +0000)
Summary: Callsites in the same basic block should share the same hotness. This patch checks for the hottest callsite in the same basic block, and use the hotness for all callsites in that basic block for early inline decisions. It also fixes the test to add "-S" so theat the "CHECK-NOT" is actually checking the content.

Reviewers: dnovillo

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D24734

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281927 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/SampleProfile.cpp
test/Transforms/SampleProfile/Inputs/einline.prof
test/Transforms/SampleProfile/early-inline.ll

index ad806addf6c17e3783590aa73c8330a574ab3937..0594063f0c7aaf97ad70322ceb2a504dc60035bd 100644 (file)
@@ -638,15 +638,20 @@ bool SampleProfileLoader::inlineHotFunctions(Function &F) {
     bool LocalChanged = false;
     SmallVector<Instruction *, 10> CIS;
     for (auto &BB : F) {
+      bool Hot = false;
+      SmallVector<Instruction *, 10> Candidates;
       for (auto &I : BB.getInstList()) {
         const FunctionSamples *FS = nullptr;
         if ((isa<CallInst>(I) || isa<InvokeInst>(I)) &&
             (FS = findCalleeFunctionSamples(I))) {
-
+          Candidates.push_back(&I);
           if (callsiteIsHot(Samples, FS))
-            CIS.push_back(&I);
+            Hot = true;
         }
       }
+      if (Hot) {
+        CIS.insert(CIS.begin(), Candidates.begin(), Candidates.end());
+      }
     }
     for (auto I : CIS) {
       InlineFunctionInfo IFI(nullptr, ACT ? &GetAssumptionCache : nullptr);
index 425d6ce22c1bc3f8708ceb1a44a28227ec2b3c58..90f41d21ca3ba888945e0731dc1e9b3884d6e22a 100644 (file)
@@ -1,3 +1,3 @@
 _Z3foov:200:100
- 1: _Z3barv:100
+ 1: _Z3barv:0
  3: _Z3barv:100
index 1ec16119e5252d868d00e996dd7cb306059c3608..6e55ab1eec744bcfce41b91c861b851961d553b9 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: opt < %s -instcombine -sample-profile -sample-profile-file=%S/Inputs/einline.prof | FileCheck %s
+; RUN: opt < %s -instcombine -sample-profile -sample-profile-file=%S/Inputs/einline.prof -S | FileCheck %s
 
 ; Checks if both call and invoke can be inlined early if their inlined
 ; instances are hot in profile.