Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 460eddf

Browse files
taewookohadrian-prantl
authored andcommitted
Do not apply redundant LastCallToStaticBonus
Summary: As written in the comments above, LastCallToStaticBonus is already applied to the cost if Caller has only one user, so it is redundant to reapply the bonus here. If the only user is not a caller, TotalSecondaryCost will not be adjusted anyway because callerWillBeRemoved is false. If there's no caller at all, we don't need to care about TotalSecondaryCost because inliningPreventsSomeOuterInline is false. Reviewers: chandlerc, eraman Reviewed By: eraman Subscribers: haicheng, davidxl, davide, llvm-commits, mehdi_amini Differential Revision: https://reviews.llvm.org/D29169 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295075 91177308-0d34-0410-b5e6-96231b3b80d8 (cherry picked from commit 17063d9)
1 parent cf6e906 commit 460eddf

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

lib/Transforms/IPO/Inliner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ shouldBeDeferred(Function *Caller, CallSite CS, InlineCost IC,
325325
// one is set very low by getInlineCost, in anticipation that Caller will
326326
// be removed entirely. We did not account for this above unless there
327327
// is only one caller of Caller.
328-
if (callerWillBeRemoved && !Caller->use_empty())
328+
if (callerWillBeRemoved && !Caller->hasOneUse())
329329
TotalSecondaryCost -= InlineConstants::LastCallToStaticBonus;
330330

331331
if (inliningPreventsSomeOuterInline && TotalSecondaryCost < IC.getCost())
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
; The goal of this test is checking if LastCallToStaticBonus is applied
2+
; correctly while deciding inline deferral. For the test code below, when
3+
; inliner evaluates the callsite of bar->baz, it checks if inlining of bar->baz
4+
; prevents ininling of foo->bar, even when foo->bar inlining is more beneficial
5+
; than bar->baz inlining. As LastCallToStaticBonus has a massive value, and
6+
; both baz and bar has only one caller, the cost of foo->bar inlining and
7+
; bar->baz inlining should be non-trivial for inliner to compute that bar->baz
8+
; inlining can actaully prevent foo->bar inlining. To make the cost of these
9+
; callsites big enough, loop unrolling pass with very high threshold is used to
10+
; preprocess the test.
11+
12+
; RUN: opt < %s -loop-unroll -inline -unroll-threshold=15000 -inline-threshold=250 -S | FileCheck %s
13+
; CHECK-LABEL: define internal i32 @bar()
14+
15+
define internal i32 @baz() {
16+
entry:
17+
br label %bb1
18+
19+
bb1:
20+
%ind = phi i32 [ 0, %entry ], [ %inc, %bb1 ]
21+
call void @extern()
22+
%inc = add nsw i32 %ind, 1
23+
%cmp = icmp sgt i32 %inc, 510
24+
br i1 %cmp, label %ret, label %bb1
25+
26+
ret:
27+
ret i32 0
28+
}
29+
30+
define internal i32 @bar() {
31+
entry:
32+
br label %bb1
33+
34+
bb1:
35+
%ind = phi i32 [ 0, %entry ], [ %inc, %bb1 ]
36+
call void @extern()
37+
%inc = add nsw i32 %ind, 1
38+
%cmp = icmp sgt i32 %inc, 510
39+
br i1 %cmp, label %ret, label %bb1
40+
41+
ret:
42+
call i32 @baz()
43+
ret i32 0
44+
}
45+
46+
define i32 @foo() {
47+
entry:
48+
call i32 @bar()
49+
ret i32 0
50+
}
51+
52+
declare void @extern()

0 commit comments

Comments
 (0)