[llvm] r305009 - Do not early-inline recursive calls in sample profile loader.
Dehao Chen via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 8 13:11:57 PDT 2017
Author: dehao
Date: Thu Jun 8 15:11:57 2017
New Revision: 305009
URL: http://llvm.org/viewvc/llvm-project?rev=305009&view=rev
Log:
Do not early-inline recursive calls in sample profile loader.
Summary: Early-inlining of recursive call makes the code size bloat exponentially. We should not disable it.
Reviewers: davidxl, dnovillo, iteratee
Reviewed By: iteratee
Subscribers: iteratee, llvm-commits, sanjoy
Differential Revision: https://reviews.llvm.org/D34017
Modified:
llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp
llvm/trunk/test/Transforms/SampleProfile/Inputs/indirect-call.prof
llvm/trunk/test/Transforms/SampleProfile/indirect-call.ll
Modified: llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp?rev=305009&r1=305008&r2=305009&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp Thu Jun 8 15:11:57 2017
@@ -695,6 +695,13 @@ bool SampleProfileLoader::inlineHotFunct
CallSite(I).isIndirectCall())
for (const auto *FS : findIndirectCallFunctionSamples(*I)) {
auto CalleeFunctionName = FS->getName();
+ // If it is a recursive call, we do not inline it as it could bloat
+ // the code exponentially. There is way to better handle this, e.g.
+ // clone the caller first, and inline the cloned caller if it is
+ // recursive. As llvm does not inline recursive calls, we will simply
+ // ignore it instead of handling it explicitly.
+ if (CalleeFunctionName == F.getName())
+ continue;
const char *Reason = "Callee function not available";
auto R = SymbolMap.find(CalleeFunctionName);
if (R == SymbolMap.end())
Modified: llvm/trunk/test/Transforms/SampleProfile/Inputs/indirect-call.prof
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SampleProfile/Inputs/indirect-call.prof?rev=305009&r1=305008&r2=305009&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SampleProfile/Inputs/indirect-call.prof (original)
+++ llvm/trunk/test/Transforms/SampleProfile/Inputs/indirect-call.prof Thu Jun 8 15:11:57 2017
@@ -17,3 +17,6 @@ test_inline_strip:3000:0
test_inline_strip_conflict:3000:0
1: foo_inline_strip_conflict:3000
1: 3000
+test_norecursive_inline:3000:0
+ 1: test_norecursive_inline:3000
+ 20: 3000
Modified: llvm/trunk/test/Transforms/SampleProfile/indirect-call.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SampleProfile/indirect-call.ll?rev=305009&r1=305008&r2=305009&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SampleProfile/indirect-call.ll (original)
+++ llvm/trunk/test/Transforms/SampleProfile/indirect-call.ll Thu Jun 8 15:11:57 2017
@@ -69,7 +69,18 @@ define void @test_noinline(void ()*) !db
ret void
}
+; CHECK-LABEL: @test_norecursive_inline
+; If the indirect call target is the caller, we should not promote it.
+define void @test_norecursive_inline() !dbg !24 {
+; CHECK-NOT: icmp
+; CHECK: call
+ %1 = load void ()*, void ()** @y, align 8
+ call void %1(), !dbg !25
+ ret void
+}
+
@x = global i32 0, align 4
+ at y = global void ()* null, align 8
define i32* @foo_inline1(i32* %x) !dbg !14 {
ret i32* %x
@@ -142,3 +153,5 @@ define void @test_direct() !dbg !22 {
!21 = distinct !DISubprogram(name: "foo_direct", scope: !1, file: !1, line: 21, unit: !0)
!22 = distinct !DISubprogram(name: "test_direct", scope: !1, file: !1, line: 22, unit: !0)
!23 = !DILocation(line: 23, scope: !22)
+!24 = distinct !DISubprogram(name: "test_norecursive_inline", scope: !1, file: !1, line: 12, unit: !0)
+!25 = !DILocation(line: 13, scope: !24)
More information about the llvm-commits
mailing list