[llvm] f415d74 - [SampleProfile] Handle the case when the option `MaxNumPromotions` is zero.
via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 22 21:45:03 PST 2022
Author: minglotus-6
Date: 2022-02-22T21:44:32-08:00
New Revision: f415d74d1df3995795c889333d493b0dcc31a863
URL: https://github.com/llvm/llvm-project/commit/f415d74d1df3995795c889333d493b0dcc31a863
DIFF: https://github.com/llvm/llvm-project/commit/f415d74d1df3995795c889333d493b0dcc31a863.diff
LOG: [SampleProfile] Handle the case when the option `MaxNumPromotions` is zero.
In places where `MaxNumPromotions` is used to allocated an array, bail out early to prevent allocating an array of length 0.
Differential Revision: https://reviews.llvm.org/D120295
Added:
Modified:
llvm/lib/Transforms/IPO/SampleProfile.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index fc0b6f5991a1f..5985281019b0a 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -841,6 +841,13 @@ static void
updateIDTMetaData(Instruction &Inst,
const SmallVectorImpl<InstrProfValueData> &CallTargets,
uint64_t Sum) {
+ // Bail out early if MaxNumPromotions is zero.
+ // This prevents allocating an array of zero length below.
+ //
+ // Note `updateIDTMetaData` is called in two places so check
+ // `MaxNumPromotions` inside it.
+ if (MaxNumPromotions == 0)
+ return;
uint32_t NumVals = 0;
// OldSum is the existing total count in the value profile data.
uint64_t OldSum = 0;
@@ -924,6 +931,10 @@ updateIDTMetaData(Instruction &Inst,
bool SampleProfileLoader::tryPromoteAndInlineCandidate(
Function &F, InlineCandidate &Candidate, uint64_t SumOrigin, uint64_t &Sum,
SmallVector<CallBase *, 8> *InlinedCallSite) {
+ // Bail out early if MaxNumPromotions is zero.
+ // This prevents allocating an array of zero length in callees below.
+ if (MaxNumPromotions == 0)
+ return false;
auto CalleeFunctionName = Candidate.CalleeSamples->getFuncName();
auto R = SymbolMap.find(CalleeFunctionName);
if (R == SymbolMap.end() || !R->getValue())
More information about the llvm-commits
mailing list