summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/InlineCost.cpp
diff options
context:
space:
mode:
authorJun Bum Lim <junbuml@codeaurora.org>2016-02-01 20:55:11 +0000
committerJun Bum Lim <junbuml@codeaurora.org>2016-02-01 20:55:11 +0000
commit53907161cc20292fd7de53e8e1f0a7ff105076a7 (patch)
treee83368482d34982de95bdc96c63b775636b9a37a /llvm/lib/Analysis/InlineCost.cpp
parent064261da160e3a63e0c6e0b3e4402880f1475a6e (diff)
downloadbcm5719-llvm-53907161cc20292fd7de53e8e1f0a7ff105076a7.tar.gz
bcm5719-llvm-53907161cc20292fd7de53e8e1f0a7ff105076a7.zip
Avoid inlining call sites in unreachable-terminated block
Summary: If the normal destination of the invoke or the parent block of the call site is unreachable-terminated, there is little point in inlining the call site unless there is literally zero cost. Unlike my previous change (D15289), this change specifically handle the call sites followed by unreachable in the same basic block for call or in the normal destination for the invoke. This change could be a reasonable first step to conservatively inline call sites leading to an unreachable-terminated block while BFI / BPI is not yet available in inliner. Reviewers: manmanren, majnemer, hfinkel, davidxl, mcrosier, dblaikie, eraman Subscribers: dblaikie, davidxl, mcrosier, llvm-commits Differential Revision: http://reviews.llvm.org/D16616 llvm-svn: 259403
Diffstat (limited to 'llvm/lib/Analysis/InlineCost.cpp')
-rw-r--r--llvm/lib/Analysis/InlineCost.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index 18d65a0c129..387077bb013 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -1214,15 +1214,26 @@ bool CallAnalyzer::analyzeCall(CallSite CS) {
if (OnlyOneCallAndLocalLinkage)
Cost += InlineConstants::LastCallToStaticBonus;
- // If the instruction after the call, or if the normal destination of the
- // invoke is an unreachable instruction, the function is noreturn. As such,
- // there is little point in inlining this unless there is literally zero
- // cost.
+ // If the normal destination of the invoke or the parent block of the call
+ // site is unreachable-terminated, there is little point in inlining this
+ // unless there is literally zero cost.
+ // FIXME: Note that it is possible that an unreachable-terminated block has a
+ // hot entry. For example, in below scenario inlining hot_call_X() may be
+ // beneficial :
+ // main() {
+ // hot_call_1();
+ // ...
+ // hot_call_N()
+ // exit(0);
+ // }
+ // For now, we are not handling this corner case here as it is rare in real
+ // code. In future, we should elaborate this based on BPI and BFI in more
+ // general threshold adjusting heuristics in updateThreshold().
Instruction *Instr = CS.getInstruction();
if (InvokeInst *II = dyn_cast<InvokeInst>(Instr)) {
- if (isa<UnreachableInst>(II->getNormalDest()->begin()))
+ if (isa<UnreachableInst>(II->getNormalDest()->getTerminator()))
Threshold = 0;
- } else if (isa<UnreachableInst>(++BasicBlock::iterator(Instr)))
+ } else if (isa<UnreachableInst>(Instr->getParent()->getTerminator()))
Threshold = 0;
// If this function uses the coldcc calling convention, prefer not to inline
OpenPOWER on IntegriCloud