[llvm] r288024 - [InlineCost] Reduce inline thresholds to compensate for cost changes

James Molloy via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 28 03:07:37 PST 2016


Author: jamesm
Date: Mon Nov 28 05:07:37 2016
New Revision: 288024

URL: http://llvm.org/viewvc/llvm-project?rev=288024&view=rev
Log:
[InlineCost] Reduce inline thresholds to compensate for cost changes

In r286814, the algorithm for calculating inline costs changed. This
caused more inlining to take place which is especially apparent
in optsize and minsize modes.

As the cost calculation removed a skewed behaviour (we were inconsistent
about the cost of calls) it isn't possible to update the thresholds to
get exactly the same behaviour as before. However, this threshold change
accounts for the very common case where an inline candidate has no
calls within it. In this case, r286814 would inline around 5-6 more (IR)
instructions.

The changes to -Oz have been heavily benchmarked. The "obvious" value
for the inline threshold at -Oz is zero, but due to inaccuracies in the
inline heuristics this can actually cause code size increases due to
not inlining key thunk functions (that then disappear). Experimentally,
5 was the sweet spot for code size over the test-suite.

For -Os, this change removes the outlier results shown up by green dragon
(http://104.154.54.203/db_default/v4/nts/13248).

Fixes D26848.

Modified:
    llvm/trunk/include/llvm/Analysis/InlineCost.h
    llvm/trunk/test/Transforms/Inline/ephemeral.ll
    llvm/trunk/test/Transforms/Inline/inline-fp.ll

Modified: llvm/trunk/include/llvm/Analysis/InlineCost.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/InlineCost.h?rev=288024&r1=288023&r2=288024&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/InlineCost.h (original)
+++ llvm/trunk/include/llvm/Analysis/InlineCost.h Mon Nov 28 05:07:37 2016
@@ -30,13 +30,13 @@ class TargetTransformInfo;
 namespace InlineConstants {
 // Various thresholds used by inline cost analysis.
 /// Use when optsize (-Os) is specified.
-const int OptSizeThreshold = 75;
+const int OptSizeThreshold = 50;
 
 /// Use when minsize (-Oz) is specified.
-const int OptMinSizeThreshold = 25;
+const int OptMinSizeThreshold = 5;
 
 /// Use when -O3 is specified.
-const int OptAggressiveThreshold = 275;
+const int OptAggressiveThreshold = 250;
 
 // Various magic constants used to adjust heuristics.
 const int InstrCost = 5;

Modified: llvm/trunk/test/Transforms/Inline/ephemeral.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/ephemeral.ll?rev=288024&r1=288023&r2=288024&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/Inline/ephemeral.ll (original)
+++ llvm/trunk/test/Transforms/Inline/ephemeral.ll Mon Nov 28 05:07:37 2016
@@ -2,10 +2,8 @@
 
 @a = global i32 4
 
-define i1 @inner() {
+define i32 @inner() {
   %a1 = load volatile i32, i32* @a
-  %x1 = add i32 %a1, %a1
-  %c = icmp eq i32 %x1, 0
 
   ; Here are enough instructions to prevent inlining, but because they are used
   ; only by the @llvm.assume intrinsic, they're free (and, thus, inlining will
@@ -14,18 +12,18 @@ define i1 @inner() {
   %a3 = sub i32 %a1, 5
   %a4 = udiv i32 %a3, -13
   %a5 = mul i32 %a4, %a4
-  %a6 = add i32 %a5, %x1
+  %a6 = add i32 %a5, %a5
   %ca = icmp sgt i32 %a6, -7
   tail call void @llvm.assume(i1 %ca)
 
-  ret i1 %c
+  ret i32 %a1
 }
 
 ; @inner() should be inlined for -Oz.
 ; CHECK-NOT: call i1 @inner
-define i1 @outer() optsize {
-   %r = call i1 @inner()
-   ret i1 %r
+define i32 @outer() optsize {
+   %r = call i32 @inner()
+   ret i32 %r
 }
 
 declare void @llvm.assume(i1) nounwind

Modified: llvm/trunk/test/Transforms/Inline/inline-fp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/inline-fp.ll?rev=288024&r1=288023&r2=288024&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/Inline/inline-fp.ll (original)
+++ llvm/trunk/test/Transforms/Inline/inline-fp.ll Mon Nov 28 05:07:37 2016
@@ -132,5 +132,5 @@ declare float @fabsf(float) optsize mins
 
 declare float @llvm.pow.f32(float, float) optsize minsize
 
-attributes #0 = { minsize optsize }
-attributes #1 = { minsize optsize "use-soft-float"="true" }
+attributes #0 = { optsize }
+attributes #1 = { optsize "use-soft-float"="true" }




More information about the llvm-commits mailing list