]> granicus.if.org Git - llvm/commitdiff
Revert [InlineCost] cleanup calculations of Cost and Threshold
authorJordan Rupprecht <rupprecht@google.com>
Wed, 3 Jul 2019 04:01:51 +0000 (04:01 +0000)
committerJordan Rupprecht <rupprecht@google.com>
Wed, 3 Jul 2019 04:01:51 +0000 (04:01 +0000)
This reverts r364422 (git commit 1a3dc761860d620ac8ed7e32a4285952142f780b)

The inlining cost calculation is incorrect, leading to stack overflow due to large stack frames from heavy inlining.

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

lib/Analysis/InlineCost.cpp
test/LTO/Resolution/X86/diagnostic-handler-remarks-with-hotness.ll
test/LTO/Resolution/X86/diagnostic-handler-remarks.ll
test/LTO/X86/diagnostic-handler-remarks-with-hotness.ll
test/LTO/X86/diagnostic-handler-remarks.ll
test/Transforms/Inline/ARM/inline-fp.ll

index b7b58d8aca3aebf25aca703cadf37dcdd1c70139..3cb56f8cccf59c7184f3be7b3a60e1969df2c7fb 100644 (file)
@@ -897,15 +897,7 @@ void CallAnalyzer::updateThreshold(CallBase &Call, Function &Callee) {
   // and the callsite.
   int SingleBBBonusPercent = 50;
   int VectorBonusPercent = 150;
-
-  int LastCallToStaticBonus = 0;
-  bool OnlyOneCallAndLocalLinkage =
-      F.hasLocalLinkage() && F.hasOneUse() && &F == Call.getCalledFunction();
-  // If there is only one call of the function, and it has internal linkage,
-  // we can allow to inline pretty anything as it will lead to size reduction
-  // anyway.
-  if (OnlyOneCallAndLocalLinkage)
-    LastCallToStaticBonus = InlineConstants::LastCallToStaticBonus;
+  int LastCallToStaticBonus = InlineConstants::LastCallToStaticBonus;
 
   // Lambda to set all the above bonus and bonus percentages to 0.
   auto DisallowAllBonuses = [&]() {
@@ -978,13 +970,20 @@ void CallAnalyzer::updateThreshold(CallBase &Call, Function &Callee) {
     }
   }
 
-  // Take the target-specific inlining threshold multiplier into account.
+  // Finally, take the target-specific inlining threshold multiplier into
+  // account.
   Threshold *= TTI.getInliningThresholdMultiplier();
 
   SingleBBBonus = Threshold * SingleBBBonusPercent / 100;
   VectorBonus = Threshold * VectorBonusPercent / 100;
 
-  Threshold += LastCallToStaticBonus;
+  bool OnlyOneCallAndLocalLinkage =
+      F.hasLocalLinkage() && F.hasOneUse() && &F == Call.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.
+  if (OnlyOneCallAndLocalLinkage)
+    Cost -= LastCallToStaticBonus;
 }
 
 bool CallAnalyzer::visitCmpInst(CmpInst &I) {
@@ -1331,10 +1330,9 @@ bool CallAnalyzer::visitCallBase(CallBase &Call) {
   CallAnalyzer CA(TTI, GetAssumptionCache, GetBFI, PSI, ORE, *F, Call,
                   IndirectCallParams);
   if (CA.analyzeCall(Call)) {
-    // We were able to inline the indirect call! Increase the threshold
-    // with the bonus we want to apply (less the cost of inlinee).
-    // Make sure the bonus doesn't go below zero.
-    Threshold += std::max(0, CA.getThreshold() - CA.getCost());
+    // We were able to inline the indirect call! Subtract the cost from the
+    // threshold to get the bonus we want to apply, but don't go below zero.
+    Cost -= std::max(0, CA.getThreshold() - CA.getCost());
   }
 
   if (!F->onlyReadsMemory())
index 6b5a338e412ef0fa9ad8ccda779ef5c152eee25e..9932f527dc602a485a5ca923b149ba5d2d410592 100644 (file)
 ; YAML-NEXT:   - Caller:          main
 ; YAML-NEXT:   - String:          ' with '
 ; YAML-NEXT:   - String:          '(cost='
-; YAML-NEXT:   - Cost:            '0'
+; YAML-NEXT:   - Cost:            '-15000'
 ; YAML-NEXT:   - String:          ', threshold='
-; YAML-NEXT:   - Threshold:       '15337'
+; YAML-NEXT:   - Threshold:       '337'
 ; YAML-NEXT:   - String:          ')'
 ; YAML-NEXT: ...
 
-; CHECK: tinkywinky inlined into main with (cost=0, threshold=15337) (hotness: 300)
+; CHECK: tinkywinky inlined into main with (cost=-15000, threshold=337) (hotness: 300)
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-scei-ps4"
index 72f10235a81f261df7926d506933e82f92bfcdb4..beb0f4fa49b8663364e3457f744828dd5ef173ec 100644 (file)
@@ -30,9 +30,9 @@
 ; YAML-NEXT:   - Caller:          main
 ; YAML-NEXT:   - String:          ' with '
 ; YAML-NEXT:   - String:          '(cost='
-; YAML-NEXT:   - Cost:            '0'
+; YAML-NEXT:   - Cost:            '-15000'
 ; YAML-NEXT:   - String:          ', threshold='
-; YAML-NEXT:   - Threshold:       '15337'
+; YAML-NEXT:   - Threshold:       '337'
 ; YAML-NEXT:   - String:          ')'
 ; YAML-NEXT: ...
 
index ab4003d0e09b5c6d6f77eda31ea60ec6e0d6888d..d1dddf1a71f01778b5bec260462b1264b0ecf69b 100644 (file)
@@ -19,9 +19,9 @@
 ; YAML-NEXT:   - Caller:          main
 ; YAML-NEXT:   - String:          ' with '
 ; YAML-NEXT:   - String:          '(cost='
-; YAML-NEXT:   - Cost:            '0'
+; YAML-NEXT:   - Cost:            '-15000'
 ; YAML-NEXT:   - String:          ', threshold='
-; YAML-NEXT:   - Threshold:       '15337'
+; YAML-NEXT:   - Threshold:       '337'
 ; YAML-NEXT:   - String:          ')'
 ; YAML-NEXT: ...
 
index dd4086fb58793d0ae55fcfc7bcdf6e428001fac6..94f88ec43c5c71ffc83c9804c8c92d4c3c8834f9 100644 (file)
@@ -55,9 +55,9 @@
 ; YAML-NEXT:   - Caller:          main
 ; YAML-NEXT:   - String:          ' with '
 ; YAML-NEXT:   - String:          '(cost='
-; YAML-NEXT:   - Cost:            '0'
+; YAML-NEXT:   - Cost:            '-15000'
 ; YAML-NEXT:   - String:          ', threshold='
-; YAML-NEXT:   - Threshold:       '15337'
+; YAML-NEXT:   - Threshold:       '337'
 ; YAML-NEXT:   - String:          ')'
 ; YAML-NEXT: ...
 
index a8e486eb0a538a6abe22cbda550eec4d0bc1281e..1d74dfd15b187a790bf10129e315e197bf73ca4d 100644 (file)
@@ -7,7 +7,7 @@
 ; NOFP-DAG: single not inlined into test_single because too costly to inline (cost=125, threshold=75)
 ; NOFP-DAG: single not inlined into test_single because too costly to inline (cost=125, threshold=75)
 ; NOFP-DAG: single_cheap inlined into test_single_cheap with (cost=-15, threshold=75)
-; NOFP-DAG: single_cheap inlined into test_single_cheap with (cost=-15, threshold=15075)
+; NOFP-DAG: single_cheap inlined into test_single_cheap with (cost=-15015, threshold=75)
 ; NOFP-DAG: double not inlined into test_double because too costly to inline (cost=125, threshold=75)
 ; NOFP-DAG: double not inlined into test_double because too costly to inline (cost=125, threshold=75)
 ; NOFP-DAG: single_force_soft not inlined into test_single_force_soft because too costly to inline (cost=125, threshold=75)
 ; NOFP-DAG: single_force_soft_fneg not inlined into test_single_force_soft_fneg because too costly to inline (cost=100, threshold=75)
 
 ; FULLFP-DAG: single inlined into test_single with (cost=0, threshold=75)
-; FULLFP-DAG: single inlined into test_single with (cost=0, threshold=15075)
+; FULLFP-DAG: single inlined into test_single with (cost=-15000, threshold=75)
 ; FULLFP-DAG: single_cheap inlined into test_single_cheap with (cost=-15, threshold=75)
-; FULLFP-DAG: single_cheap inlined into test_single_cheap with (cost=-15, threshold=15075)
+; FULLFP-DAG: single_cheap inlined into test_single_cheap with (cost=-15015, threshold=75)
 ; FULLFP-DAG: double inlined into test_double with (cost=0, threshold=75)
-; FULLFP-DAG: double inlined into test_double with (cost=0, threshold=15075)
+; FULLFP-DAG: double inlined into test_double with (cost=-15000, threshold=75)
 ; FULLFP-DAG: single_force_soft not inlined into test_single_force_soft because too costly to inline (cost=125, threshold=75)
 ; FULLFP-DAG: single_force_soft not inlined into test_single_force_soft because too costly to inline (cost=125, threshold=75)
 ; FULLFP-DAG: single_force_soft_fneg not inlined into test_single_force_soft_fneg because too costly to inline (cost=100, threshold=75)
 ; FULLFP-DAG: single_force_soft_fneg not inlined into test_single_force_soft_fneg because too costly to inline (cost=100, threshold=75)
 
 ; SINGLEFP-DAG: single inlined into test_single with (cost=0, threshold=75)
-; SINGLEFP-DAG: single inlined into test_single with (cost=0, threshold=15075)
+; SINGLEFP-DAG: single inlined into test_single with (cost=-15000, threshold=75)
 ; SINGLEFP-DAG: single_cheap inlined into test_single_cheap with (cost=-15, threshold=75)
-; SINGLEFP-DAG: single_cheap inlined into test_single_cheap with (cost=-15, threshold=15075)
+; SINGLEFP-DAG: single_cheap inlined into test_single_cheap with (cost=-15015, threshold=75)
 ; SINGLEFP-DAG: double not inlined into test_double because too costly to inline (cost=125, threshold=75)
 ; SINGLEFP-DAG: double not inlined into test_double because too costly to inline (cost=125, threshold=75)
 ; SINGLEFP-DAG: single_force_soft not inlined into test_single_force_soft because too costly to inline (cost=125, threshold=75)