[llvm] [MemProf] Support cold-only and min hint when optimizing existing hot/cold new (PR #218803)

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 25 19:53:29 PDT 2026


================
@@ -1809,6 +1834,24 @@ Value *LibCallSimplifier::optimizeNew(CallInst *CI, IRBuilderBase &B,
   else
     return nullptr;
 
+  bool ShouldOptimizeExisting =
+      OptimizeExistingHotColdNew == OptimizeExistingHotColdNewKind::Always ||
+      (OptimizeExistingHotColdNew == OptimizeExistingHotColdNewKind::Cold &&
+       IsCold);
+
+  Value *HotColdVal = B.getInt8(HotCold);
+  auto getHotColdHintForExisting = [&](uint8_t HotCold) -> Value * {
+    if (!MinExistingHotColdNewHint)
+      return HotColdVal;
+    Value *ExistingHint = CI->getArgOperand(CI->arg_size() - 1);
+    if (auto *CIHint = dyn_cast<ConstantInt>(ExistingHint))
+      return B.getInt8(
+          std::min(HotCold, static_cast<uint8_t>(CIHint->getZExtValue())));
+    if (ExistingHint->getType() != B.getInt8Ty())
+      ExistingHint = B.CreateTruncOrBitCast(ExistingHint, B.getInt8Ty());
+    return B.CreateBinaryIntrinsic(Intrinsic::umin, ExistingHint, HotColdVal);
----------------
teresajohnson wrote:

confirmed. I went ahead and made that change and there was no impact to the tests

https://github.com/llvm/llvm-project/pull/218803


More information about the llvm-commits mailing list