[llvm] r259120 - Lower inlining threshold when the caller has minsize attribute.

Easwaran Raman via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 28 15:44:42 PST 2016


Author: eraman
Date: Thu Jan 28 17:44:41 2016
New Revision: 259120

URL: http://llvm.org/viewvc/llvm-project?rev=259120&view=rev
Log:
Lower inlining threshold when the caller has minsize attribute.

When the caller has optsize attribute, we reduce the inlinining threshold
to OptSizeThreshold (=75) if it is not already lower than that. We don't do
the same for minsize and I suspect it was not intentional. This also addresses
a FIXME regarding checking optsize attribute explicitly instead of using the
right wrapper.

Differential Revision: http://reviews.llvm.org/D16493


Modified:
    llvm/trunk/lib/Analysis/InlineCost.cpp
    llvm/trunk/test/Transforms/Inline/inline-optsize.ll

Modified: llvm/trunk/lib/Analysis/InlineCost.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InlineCost.cpp?rev=259120&r1=259119&r2=259120&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InlineCost.cpp (original)
+++ llvm/trunk/lib/Analysis/InlineCost.cpp Thu Jan 28 17:44:41 2016
@@ -573,16 +573,16 @@ bool CallAnalyzer::isKnownNonNullInCalle
 }
 
 void CallAnalyzer::updateThreshold(CallSite CS, Function &Callee) {
-  // If -inline-threshold is not given, listen to the optsize attribute when it
-  // would decrease the threshold.
+  // If -inline-threshold is not given, listen to the optsize and minsize
+  // attributes when they would decrease the threshold.
   Function *Caller = CS.getCaller();
 
-  // FIXME: Use Function::optForSize()
-  bool OptSize = Caller->hasFnAttribute(Attribute::OptimizeForSize);
-
-  if (!(DefaultInlineThreshold.getNumOccurrences() > 0) && OptSize &&
-      OptSizeThreshold < Threshold)
-    Threshold = OptSizeThreshold;
+  if (!(DefaultInlineThreshold.getNumOccurrences() > 0)) {
+    if (Caller->optForMinSize() && OptMinSizeThreshold < Threshold)
+      Threshold = OptMinSizeThreshold;
+    else if (Caller->optForSize() && OptSizeThreshold < Threshold)
+      Threshold = OptSizeThreshold;
+  }
 
   // If profile information is available, use that to adjust threshold of hot
   // and cold functions.

Modified: llvm/trunk/test/Transforms/Inline/inline-optsize.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/inline-optsize.ll?rev=259120&r1=259119&r2=259120&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/Inline/inline-optsize.ll (original)
+++ llvm/trunk/test/Transforms/Inline/inline-optsize.ll Thu Jan 28 17:44:41 2016
@@ -1,5 +1,6 @@
 ; RUN: opt -S -Oz < %s | FileCheck %s -check-prefix=OZ
 ; RUN: opt -S -O2 < %s | FileCheck %s -check-prefix=O2
+; RUN: opt -S -Os < %s | FileCheck %s -check-prefix=OS
 
 ; The inline threshold for a function with the optsize attribute is currently
 ; the same as the global inline threshold for -Os. Check that the optsize
@@ -24,10 +25,20 @@ define i32 @inner() {
   ret i32 %x5
 }
 
-; @inner() should be inlined for -O2 but not for -Oz.
+; @inner() should be inlined for -O2 and -Os but not for -Oz.
 ; OZ: call
 ; O2-NOT: call
+; OS-NOT: call
 define i32 @outer() optsize {
    %r = call i32 @inner()
    ret i32 %r
 }
+
+; @inner() should not be inlined for -O2, -Os and -Oz.
+; OZ: call
+; O2: call
+; OS: call
+define i32 @outer2() minsize {
+   %r = call i32 @inner()
+   ret i32 %r
+}




More information about the llvm-commits mailing list