[PATCH] D22261: [InlineCost] Set minsize inline threshold to 0

James Molloy via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 12 01:33:39 PDT 2016


jmolloy created this revision.
jmolloy added reviewers: chandlerc, hfinkel, mehdi_amini, ab.
jmolloy added a subscriber: llvm-commits.
jmolloy set the repository for this revision to rL LLVM.

"minsize", unlike other optimization levels, has a well defined expectation of how the inliner should behave. It shouldn't increase code size.

Therefore set the threshold to 0. This still allows the inliner to inline trivial functions that are smaller than the callsite cost, modulo a bug that I intend to fix in a followup where the cost calcualation doesn't take into account the removal of the call instruction at the callsite.

Repository:
  rL LLVM

http://reviews.llvm.org/D22261

Files:
  lib/Analysis/InlineCost.cpp
  test/Transforms/Inline/ephemeral.ll
  test/Transforms/Inline/inline-fp.ll

Index: test/Transforms/Inline/inline-fp.ll
===================================================================
--- test/Transforms/Inline/inline-fp.ll
+++ test/Transforms/Inline/inline-fp.ll
@@ -132,5 +132,5 @@
 
 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" }
Index: test/Transforms/Inline/ephemeral.ll
===================================================================
--- test/Transforms/Inline/ephemeral.ll
+++ test/Transforms/Inline/ephemeral.ll
@@ -1,32 +1,30 @@
-; RUN: opt -S -Oz %s | FileCheck %s
+; RUN: opt -S -inline %s | FileCheck %s
 
 @a = global i32 4
 
-define i1 @inner() {
-  %a1 = load volatile i32, i32* @a
+define i32 @inner() minsize optsize {
+  %a1 = load 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
   ; still happen).
   %a2 = mul i32 %a1, %a1
-  %a3 = sub i32 %a1, 5
+  %a3 = sub i32 %a2, 5
   %a4 = udiv i32 %a3, -13
   %a5 = mul i32 %a4, %a4
   %a6 = add i32 %a5, %x1
   %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() minsize optsize {
+   %r = call i32 @inner()
+   ret i32 %r
 }
 
 declare void @llvm.assume(i1) nounwind
-
Index: lib/Analysis/InlineCost.cpp
===================================================================
--- lib/Analysis/InlineCost.cpp
+++ lib/Analysis/InlineCost.cpp
@@ -45,7 +45,7 @@
 const int OptSizeThreshold = 75;
 
 // Threshold to use when -Oz is specified (and there is no -inline-threshold).
-const int OptMinSizeThreshold = 25;
+const int OptMinSizeThreshold = 0;
 
 // Threshold to use when -O[34] is specified (and there is no
 // -inline-threshold).


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22261.63651.patch
Type: text/x-patch
Size: 2110 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160712/91506d7b/attachment.bin>


More information about the llvm-commits mailing list