[PATCH] D15356: Test case for indirect call bonus in inline cost analysis

Easwaran Raman via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 8 15:17:09 PST 2015


eraman created this revision.
eraman added a reviewer: chandlerc.
eraman added subscribers: llvm-commits, davidxl.
eraman set the repository for this revision to rL LLVM.

This is a test case for http://reviews.llvm.org/D15245 that uses the updated threshold for calculating indirect call bonus when baz->bar inlining would result in the indirect call passed to bar being resolved to foo.

To test the change, I needed the following properties:

* Cost of baz->bar (C1) is greater than the threshold (T1 = 115) without applying any indirect call bonus
* Let C2 be the cost of bar->foo inlining and T2 = InlineConstants::IndirectCallThreshold = 100). C1 > T1 + max(0, T2-C2), and

* C1 <= T1 + max(0, 1.5*T2 - C2). The 1.5 comes from the addition of single BB bonus. When considering bar->foo inlining, CostAnalyzer's getThreshold() will return 1.5*T2.


This looks very brittle to me. If IndirectCallThreshold and the single BB bonus were options to opt, then this would be much better, imo.

Repository:
  rL LLVM

http://reviews.llvm.org/D15356

Files:
  test/Transforms/Inline/indirect-call-inlining-bonus.ll

Index: test/Transforms/Inline/indirect-call-inlining-bonus.ll
===================================================================
--- test/Transforms/Inline/indirect-call-inlining-bonus.ll
+++ test/Transforms/Inline/indirect-call-inlining-bonus.ll
@@ -0,0 +1,88 @@
+; RUN: opt -inline < %s -S -o - -inline-threshold=115 | FileCheck %s
+
+; While trying to inline baz->bar, if the indirect call in bar gets resolved,
+; then the benefit of bar->foo inlining gets passed to baz->bar inlining. The
+; bonus is calculated as threshold - cost. This test checks that the threshold
+; used above includes any bonus in bar->foo inline computation. In this test,
+; foo has a single BB which results in a bonus.
+
+define i32 @foo(i32 %val) {
+  %t1 = add i32 %val, 1
+  %t2 = add i32 %t1, 1
+  %t3 = add i32 %t2, 1
+  %t4 = add i32 %t3, 1
+  %t5 = add i32 %t4, 1
+  %t6 = add i32 %t5, 1
+  %t7 = add i32 %t6, 1
+  %t8 = add i32 %t7, 1
+  %t9 = add i32 %t8, 1
+  %t10 = add i32 %t9, 1
+  %t11 = add i32 %t10, 1
+  %t12 = add i32 %t11, 1
+  %t13 = add i32 %t12, 1
+  %t14 = add i32 %t13, 1
+  %t15 = add i32 %t14, 1
+  %t16 = add i32 %t15, 1
+  %t17 = add i32 %t16, 1
+  %t18 = add i32 %t17, 1
+  %t19 = add i32 %t18, 1
+  %t20 = add i32 %t19, 1
+  %t21 = add i32 %t20, 1
+  %t22 = add i32 %t21, 1
+  %t23 = add i32 %t22, 1
+  %t24 = add i32 %t23, 1
+  %t25 = add i32 %t24, 1
+  %t26 = add i32 %t25, 1
+  %t27 = add i32 %t26, 1
+  %t28 = add i32 %t27, 1
+  %t29 = add i32 %t28, 1
+  %t30 = add i32 %t29, 1
+  ret i32 %t30
+}
+
+define i32 @bar(i32 (i32)*, i32 %val) {
+  %t1 = add i32 %val, 1
+  %t2 = add i32 %t1, 1
+  %t3 = add i32 %t2, 1
+  %t4 = add i32 %t3, 1
+  %t5 = add i32 %t4, 1
+  %t6 = add i32 %t5, 1
+  %t7 = add i32 %t6, 1
+  %t8 = add i32 %t7, 1
+  %t9 = add i32 %t8, 1
+  %t10 = add i32 %t9, 1
+  %t11 = add i32 %t10, 1
+  %t12 = add i32 %t11, 1
+  %t13 = add i32 %t12, 1
+  %t14 = add i32 %t13, 1
+  %t15 = add i32 %t14, 1
+  %t16 = add i32 %t15, 1
+  %t17 = add i32 %t16, 1
+  %t18 = add i32 %t17, 1
+  %t19 = add i32 %t18, 1
+  %t20 = add i32 %t19, 1
+  %t21 = add i32 %t20, 1
+  %t22 = add i32 %t21, 1
+  %t23 = add i32 %t22, 1
+  %t24 = add i32 %t23, 1
+  %t25 = add i32 %t24, 1
+  %t26 = add i32 %t25, 1
+  %t27 = add i32 %t26, 1
+  %t28 = add i32 %t27, 1
+  %t29 = add i32 %t28, 1
+  %t30 = add i32 %t29, 1
+  %t31 = add i32 %t30, 1
+  %t32 = add i32 %t31, 1
+  %t33 = add i32 %t32, 1
+  %t34 = add i32 %t33, 1
+  %t35 = add i32 %t34, 1
+  %res = call i32 %0(i32 %t5);
+  ret i32 %res
+}
+
+define i32 @baz(i32 %val) {
+; CHECK-LABEL: @baz(
+; CHECK-NOT: call
+  %res = call i32 @bar(i32 (i32)* @foo, i32 %val)
+  ret i32 %res
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15356.42235.patch
Type: text/x-patch
Size: 2643 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151208/6428ad8b/attachment.bin>


More information about the llvm-commits mailing list