diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp --- a/llvm/lib/Transforms/IPO/SampleProfile.cpp +++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp @@ -802,6 +802,11 @@ /// NOMORE_ICP_MAGICNUM count values in the value profile of \p Inst, we /// cannot promote for \p Inst anymore. static bool doesHistoryAllowICP(const Instruction &Inst, StringRef Candidate) { + // Bail out early if MaxNumPromotions is zero. + // This prevents allocating an array of zero length below. + if (MaxNumPromotions == 0) + return false; + uint32_t NumVals = 0; uint64_t TotalCount = 0; std::unique_ptr ValueData = @@ -841,6 +846,11 @@ updateIDTMetaData(Instruction &Inst, const SmallVectorImpl &CallTargets, uint64_t Sum) { + // Bail out early if MaxNumPromotions is zero. + // This prevents allocating an array of zero length below. + if (MaxNumPromotions == 0) + return; + uint32_t NumVals = 0; // OldSum is the existing total count in the value profile data. uint64_t OldSum = 0;