aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/InlineCost.cpp
diff options
context:
space:
mode:
authorKazu Hirata <kazu@google.com>2021-03-25 21:51:36 -0700
committerKazu Hirata <kazu@google.com>2021-03-25 21:51:36 -0700
commit3c775d93a1dda3cec3bb6c7617c4b4ab770f4af0 (patch)
tree707ddfe40e7bce718dde1bad774db4d7cae2438e /llvm/lib/Analysis/InlineCost.cpp
parentec46e03daf54fc2e69561f23486df60fea0b1655 (diff)
downloadllvm-3c775d93a1dda3cec3bb6c7617c4b4ab770f4af0.zip
llvm-3c775d93a1dda3cec3bb6c7617c4b4ab770f4af0.tar.gz
llvm-3c775d93a1dda3cec3bb6c7617c4b4ab770f4af0.tar.bz2
[InlineCost] Reject a zero entry count
This patch teaches the cost-benefit-analysis-based inliner to reject a zero entry count so that we don't trigger a divide-by-zero.
Diffstat (limited to 'llvm/lib/Analysis/InlineCost.cpp')
-rw-r--r--llvm/lib/Analysis/InlineCost.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index c02b567..538dfac 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -696,7 +696,9 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
if (!PSI->isHotCallSite(CandidateCall, CallerBFI))
return false;
- if (!F.getEntryCount())
+ // Make sure we have a nonzero entry count.
+ auto EntryCount = F.getEntryCount();
+ if (!EntryCount || !EntryCount.getCount())
return false;
BlockFrequencyInfo *CalleeBFI = &(GetBFI(F));
@@ -765,7 +767,7 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
// Compute the cycle savings per call.
auto EntryProfileCount = F.getEntryCount();
- assert(EntryProfileCount.hasValue());
+ assert(EntryProfileCount.hasValue() && EntryProfileCount.getCount());
auto EntryCount = EntryProfileCount.getCount();
CycleSavings += EntryCount / 2;
CycleSavings = CycleSavings.udiv(EntryCount);