[PATCH] D44450: [InlineCost] Don't return early when allowSizeGrowth(CS) is false

Jessica Paquette via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 14 11:50:45 PDT 2018


paquette updated this revision to Diff 138429.
paquette added a comment.

Update patch to move the LastCallToStaticBonus logic to the top of updateThreshold.


https://reviews.llvm.org/D44450

Files:
  lib/Analysis/InlineCost.cpp
  test/Transforms/Inline/ARM/unreachable.ll


Index: test/Transforms/Inline/ARM/unreachable.ll
===================================================================
--- /dev/null
+++ test/Transforms/Inline/ARM/unreachable.ll
@@ -0,0 +1,21 @@
+; RUN: opt < %s -mtriple=arm--- -S -inline | FileCheck %s
+
+declare i32* @pluto() local_unnamed_addr #0
+
+define internal void @foo() local_unnamed_addr #0 {
+bb:
+  call i32* @pluto() #0
+  ret void
+}
+
+define void @wibble() unnamed_addr #0 {
+; CHECK-LABEL: wibble
+; CHECK-NOT: @foo()
+; CHECK: %0 = call i32* @pluto()
+; CHECK-NEXT: unreachable
+bb:
+  tail call void @foo() #0
+  unreachable
+}
+
+attributes #0 = { minsize optsize }
Index: lib/Analysis/InlineCost.cpp
===================================================================
--- lib/Analysis/InlineCost.cpp
+++ lib/Analysis/InlineCost.cpp
@@ -840,24 +840,6 @@
 }
 
 void CallAnalyzer::updateThreshold(CallSite CS, Function &Callee) {
-  // If no size growth is allowed for this inlining, set Threshold to 0.
-  if (!allowSizeGrowth(CS)) {
-    Threshold = 0;
-    return;
-  }
-
-  Function *Caller = CS.getCaller();
-
-  // return min(A, B) if B is valid.
-  auto MinIfValid = [](int A, Optional<int> B) {
-    return B ? std::min(A, B.getValue()) : A;
-  };
-
-  // return max(A, B) if B is valid.
-  auto MaxIfValid = [](int A, Optional<int> B) {
-    return B ? std::max(A, B.getValue()) : A;
-  };
-
   // Various bonus percentages. These are multiplied by Threshold to get the
   // bonus values.
   // SingleBBBonus: This bonus is applied if the callee has a single reachable
@@ -883,6 +865,34 @@
   int VectorBonusPercent = 150;
   int LastCallToStaticBonus = InlineConstants::LastCallToStaticBonus;
 
+  // If this is true, then we can apply the LastCallToStaticBonus.
+  bool OnlyOneCallAndLocalLinkage =
+    F.hasLocalLinkage() && F.hasOneUse() && &F == CS.getCalledFunction();
+
+  // If no size growth is allowed in this inlining, set the threshold to 0 and
+  // apply any cost bonuses. After that, return.
+  if (!allowSizeGrowth(CS)) {
+    Threshold = 0;
+
+    // This could still be "zero-cost" if F only has one use and has local
+    // linkage. Apply the LastCallToStatic bonus if it applies.
+    if (OnlyOneCallAndLocalLinkage)
+      Cost -= LastCallToStaticBonus;
+    return;
+  }
+
+  Function *Caller = CS.getCaller();
+
+  // return min(A, B) if B is valid.
+  auto MinIfValid = [](int A, Optional<int> B) {
+    return B ? std::min(A, B.getValue()) : A;
+  };
+
+  // return max(A, B) if B is valid.
+  auto MaxIfValid = [](int A, Optional<int> B) {
+    return B ? std::max(A, B.getValue()) : A;
+  };
+
   // Lambda to set all the above bonus and bonus percentages to 0.
   auto DisallowAllBonuses = [&]() {
     SingleBBBonusPercent = 0;
@@ -961,8 +971,6 @@
   SingleBBBonus = Threshold * SingleBBBonusPercent / 100;
   VectorBonus = Threshold * VectorBonusPercent / 100;
 
-  bool OnlyOneCallAndLocalLinkage =
-      F.hasLocalLinkage() && F.hasOneUse() && &F == CS.getCalledFunction();
   // If there is only one call of the function, and it has internal linkage,
   // the cost of inlining it drops dramatically. It may seem odd to update
   // Cost in updateThreshold, but the bonus depends on the logic in this method.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44450.138429.patch
Type: text/x-patch
Size: 3225 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180314/2cad3f22/attachment.bin>


More information about the llvm-commits mailing list