[PATCH] D24734: Handle early inline for hot callsites that reside in the same basic block.

Dehao Chen via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 19 10:29:56 PDT 2016


danielcdh created this revision.
danielcdh added a reviewer: dnovillo.
danielcdh added a subscriber: llvm-commits.

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.

https://reviews.llvm.org/D24734

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

Index: test/Transforms/SampleProfile/early-inline.ll
===================================================================
--- test/Transforms/SampleProfile/early-inline.ll
+++ test/Transforms/SampleProfile/early-inline.ll
@@ -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.
Index: test/Transforms/SampleProfile/Inputs/einline.prof
===================================================================
--- test/Transforms/SampleProfile/Inputs/einline.prof
+++ test/Transforms/SampleProfile/Inputs/einline.prof
@@ -1,3 +1,3 @@
 _Z3foov:200:100
- 1: _Z3barv:100
+ 1: _Z3barv:0
  3: _Z3barv:100
Index: lib/Transforms/IPO/SampleProfile.cpp
===================================================================
--- lib/Transforms/IPO/SampleProfile.cpp
+++ lib/Transforms/IPO/SampleProfile.cpp
@@ -638,15 +638,20 @@
     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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24734.71844.patch
Type: text/x-patch
Size: 1827 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160919/980da46a/attachment.bin>


More information about the llvm-commits mailing list