[PATCH] D63034: Slightly increase LastCallToStaticBonus for cold callsites

Yi Kong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 7 16:16:33 PDT 2019


kongyi created this revision.
kongyi added reviewers: chandlerc, eraman.
Herald added subscribers: llvm-commits, dexonsmith, haicheng, hiraditya, inglorion, mehdi_amini.
Herald added a project: LLVM.

r309441 changed LastCallToStaticBonus inling bonus to 0 for cold callsites, so that the caller has better chance of getting inlined. This makes sense for large callsites but for small callsites not inlining can actually make caller larger.

      

Slightly increased the bonus from 0 to 50. This resulted in LLVM test-suite mean text size reduced by 0.02%, with no significant performance change observed.


Repository:
  rL LLVM

https://reviews.llvm.org/D63034

Files:
  llvm/lib/Analysis/InlineCost.cpp
  llvm/test/Transforms/Inline/last-call-no-bonus.ll


Index: llvm/test/Transforms/Inline/last-call-no-bonus.ll
===================================================================
--- llvm/test/Transforms/Inline/last-call-no-bonus.ll
+++ llvm/test/Transforms/Inline/last-call-no-bonus.ll
@@ -2,7 +2,7 @@
 ; to the internal functions are cold, thereby preventing the last call to
 ; static bonus from being applied.
 
-; RUN: opt < %s -passes='function(require<opt-remark-emit>,unroll),require<profile-summary>,cgscc(inline)' -unroll-threshold=15000 -inline-threshold=250 -S | FileCheck %s
+; RUN: opt < %s -passes='function(require<opt-remark-emit>,unroll),require<profile-summary>,cgscc(inline)' -unroll-threshold=15000 -inline-threshold=0 -S | FileCheck %s
 
 ; CHECK-LABEL: define internal i32 @baz
 define internal i32 @baz() {
@@ -41,6 +41,12 @@
 ret:
   ret i32 0
 }
+
+define internal i32 @bac() {
+  call void @extern()
+  ret i32 0
+}
+
 ; CHECK-LABEL: define i32 @foo
 define i32 @foo(i1 %b) {
 entry:
@@ -48,6 +54,8 @@
 bb1:
 ; CHECK: call i32 @bar
   call i32 @bar(i1 %b)
+; CHECK-NOT: call i32 @bac
+  call i32 @bac()
   br label %ret
 ret:
   ret i32 0
Index: llvm/lib/Analysis/InlineCost.cpp
===================================================================
--- llvm/lib/Analysis/InlineCost.cpp
+++ llvm/lib/Analysis/InlineCost.cpp
@@ -899,11 +899,11 @@
   int VectorBonusPercent = 150;
   int LastCallToStaticBonus = InlineConstants::LastCallToStaticBonus;
 
-  // Lambda to set all the above bonus and bonus percentages to 0.
-  auto DisallowAllBonuses = [&]() {
+  // Lambda to significantly reduce all the above bonus and bonus percentages.
+  auto ReduceAllBonuses = [&]() {
     SingleBBBonusPercent = 0;
     VectorBonusPercent = 0;
-    LastCallToStaticBonus = 0;
+    LastCallToStaticBonus = 50;
   };
 
   // Use the OptMinSizeThreshold or OptSizeThreshold knob if they are available
@@ -943,11 +943,11 @@
       Threshold = HotCallSiteThreshold.getValue();
     } else if (isColdCallSite(Call, CallerBFI)) {
       LLVM_DEBUG(dbgs() << "Cold callsite.\n");
-      // Do not apply bonuses for a cold callsite including the
+      // Significantly reduce bonuses for a cold callsite including the
       // LastCallToStatic bonus. While this bonus might result in code size
       // reduction, it can cause the size of a non-cold caller to increase
       // preventing it from being inlined.
-      DisallowAllBonuses();
+      ReduceAllBonuses();
       Threshold = MinIfValid(Threshold, Params.ColdCallSiteThreshold);
     } else if (PSI) {
       // Use callee's global profile information only if we have no way of
@@ -960,11 +960,11 @@
         Threshold = MaxIfValid(Threshold, Params.HintThreshold);
       } else if (PSI->isFunctionEntryCold(&Callee)) {
         LLVM_DEBUG(dbgs() << "Cold callee.\n");
-        // Do not apply bonuses for a cold callee including the
+        // Significantly reduce bonuses for a cold callee including the
         // LastCallToStatic bonus. While this bonus might result in code size
         // reduction, it can cause the size of a non-cold caller to increase
         // preventing it from being inlined.
-        DisallowAllBonuses();
+        ReduceAllBonuses();
         Threshold = MinIfValid(Threshold, Params.ColdThreshold);
       }
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63034.203641.patch
Type: text/x-patch
Size: 3267 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190607/76d42f73/attachment.bin>


More information about the llvm-commits mailing list