[llvm] 7d748a9 - [InstCombine][nfc] Fix assert failure with function entry count equal to zero
Alan Zhao via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 20 21:35:04 PDT 2025
Author: Alan Zhao
Date: 2025-09-20T21:33:09-07:00
New Revision: 7d748a9ceb3716a216a8b586b1d31e046bdee039
URL: https://github.com/llvm/llvm-project/commit/7d748a9ceb3716a216a8b586b1d31e046bdee039
DIFF: https://github.com/llvm/llvm-project/commit/7d748a9ceb3716a216a8b586b1d31e046bdee039.diff
LOG: [InstCombine][nfc] Fix assert failure with function entry count equal to zero
We were hitting an assert discovered in https://github.com/llvm/llvm-project/pull/157768#issuecomment-3315359832
Added:
Modified:
llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
index 20d399315fac5..4f5373846f43a 100644
--- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -796,18 +796,19 @@ bool FunctionSpecializer::run() {
if (Count && !ProfcheckDisableMetadataFixes) {
std::optional<llvm::Function::ProfileCount> MaybeCloneCount =
Clone->getEntryCount();
- assert(MaybeCloneCount && "Clone entry count was not set!");
- uint64_t CallCount = *Count + MaybeCloneCount->getCount();
- Clone->setEntryCount(CallCount);
- if (std::optional<llvm::Function::ProfileCount> MaybeOriginalCount =
- S.F->getEntryCount()) {
- uint64_t OriginalCount = MaybeOriginalCount->getCount();
- if (OriginalCount >= *Count) {
- S.F->setEntryCount(OriginalCount - *Count);
- } else {
- // This should generally not happen as that would mean there are
- // more computed calls to the function than what was recorded.
- LLVM_DEBUG(S.F->setEntryCount(0));
+ if (MaybeCloneCount) {
+ uint64_t CallCount = *Count + MaybeCloneCount->getCount();
+ Clone->setEntryCount(CallCount);
+ if (std::optional<llvm::Function::ProfileCount> MaybeOriginalCount =
+ S.F->getEntryCount()) {
+ uint64_t OriginalCount = MaybeOriginalCount->getCount();
+ if (OriginalCount >= *Count) {
+ S.F->setEntryCount(OriginalCount - *Count);
+ } else {
+ // This should generally not happen as that would mean there are
+ // more computed calls to the function than what was recorded.
+ LLVM_DEBUG(S.F->setEntryCount(0));
+ }
}
}
}
More information about the llvm-commits
mailing list