[PATCH] D120295: [SampleProfile] Handle the case when the option `MaxNumPromotions` is zero.

Mingming Liu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 21 19:18:04 PST 2022


luna created this revision.
Herald added subscribers: ormris, wenlei, hiraditya.
luna requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

In places where `MaxNumPromotions` is used to allocated an array, bail out early to prevent allocating an array of length 0.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120295

Files:
  llvm/lib/Transforms/IPO/SampleProfile.cpp


Index: llvm/lib/Transforms/IPO/SampleProfile.cpp
===================================================================
--- llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ 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<InstrProfValueData[]> ValueData =
@@ -841,6 +846,11 @@
 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.
+  if (MaxNumPromotions == 0)
+    return;
+
   uint32_t NumVals = 0;
   // OldSum is the existing total count in the value profile data.
   uint64_t OldSum = 0;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120295.410435.patch
Type: text/x-patch
Size: 1138 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220222/12a57878/attachment.bin>


More information about the llvm-commits mailing list