Skip to content

Commit e0b1dea

Browse files
committed
Make sure always-inline functions get inlined. <rdar://problem/12423986>
Without this change, when the estimated cost for inlining a function with an "alwaysinline" attribute was lower than the inlining threshold, the getInlineCost function was returning that estimated cost rather than the special InlineCost::AlwaysInlineCost value. That is fine in the normal inlining case, but it can fail when the inliner considers the opportunity cost of inlining into an internal or linkonce-odr function. It may decide not to inline the always-inline function in that case. The fix here is just to make getInlineCost always return the special value for always-inline functions. I ran into this building clang with libc++. Tablegen failed to link because of an always-inline function that was not inlined. I have been unable to reduce the testcase down to a reasonable size. llvm-svn: 165367
1 parent ec2a51c commit e0b1dea

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

llvm/lib/Analysis/InlineCost.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
142142

143143
int getThreshold() { return Threshold; }
144144
int getCost() { return Cost; }
145+
bool isAlwaysInline() { return AlwaysInline; }
145146

146147
// Keep a bunch of stats about the cost savings found so we can print them
147148
// out when debugging.
@@ -1057,7 +1058,8 @@ InlineCost InlineCostAnalyzer::getInlineCost(CallSite CS, Function *Callee,
10571058
// Check if there was a reason to force inlining or no inlining.
10581059
if (!ShouldInline && CA.getCost() < CA.getThreshold())
10591060
return InlineCost::getNever();
1060-
if (ShouldInline && CA.getCost() >= CA.getThreshold())
1061+
if (ShouldInline && (CA.isAlwaysInline() ||
1062+
CA.getCost() >= CA.getThreshold()))
10611063
return InlineCost::getAlways();
10621064

10631065
return llvm::InlineCost::get(CA.getCost(), CA.getThreshold());

0 commit comments

Comments
 (0)