[llvm] [MemProf] Support cold-only and min hint when optimizing existing hot/cold new (PR #218803)
Snehasish Kumar via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 25 19:25:04 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);
----------------
snehasish wrote:
Taking a closer look, I think we can always emit a `umin` intrinsic and `ConstantFoldCall` will simplify it to pass the param directly to the new call. Interestingly, I think we don't need a subsequent instcombine pass, when we create a new inst in simplifylibcall called from instcombine, it gets added to the worklist again [1]. So I think we could just drop L1850-1852 in this patch and the IR generated should be the same.
Up to you if you want to adopt this suggestion but we might be able to simplify the lambda (e.g. drop the HotCold param) if we do this.
[1] https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp#L170-L178
https://github.com/llvm/llvm-project/pull/218803
More information about the llvm-commits
mailing list