Skip to content

Commit 7d748a9

Browse files
committed
[InstCombine][nfc] Fix assert failure with function entry count equal to zero
We were hitting an assert discovered in #157768 (comment)
1 parent e8e0108 commit 7d748a9

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

llvm/lib/Transforms/IPO/FunctionSpecialization.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -796,18 +796,19 @@ bool FunctionSpecializer::run() {
796796
if (Count && !ProfcheckDisableMetadataFixes) {
797797
std::optional<llvm::Function::ProfileCount> MaybeCloneCount =
798798
Clone->getEntryCount();
799-
assert(MaybeCloneCount && "Clone entry count was not set!");
800-
uint64_t CallCount = *Count + MaybeCloneCount->getCount();
801-
Clone->setEntryCount(CallCount);
802-
if (std::optional<llvm::Function::ProfileCount> MaybeOriginalCount =
803-
S.F->getEntryCount()) {
804-
uint64_t OriginalCount = MaybeOriginalCount->getCount();
805-
if (OriginalCount >= *Count) {
806-
S.F->setEntryCount(OriginalCount - *Count);
807-
} else {
808-
// This should generally not happen as that would mean there are
809-
// more computed calls to the function than what was recorded.
810-
LLVM_DEBUG(S.F->setEntryCount(0));
799+
if (MaybeCloneCount) {
800+
uint64_t CallCount = *Count + MaybeCloneCount->getCount();
801+
Clone->setEntryCount(CallCount);
802+
if (std::optional<llvm::Function::ProfileCount> MaybeOriginalCount =
803+
S.F->getEntryCount()) {
804+
uint64_t OriginalCount = MaybeOriginalCount->getCount();
805+
if (OriginalCount >= *Count) {
806+
S.F->setEntryCount(OriginalCount - *Count);
807+
} else {
808+
// This should generally not happen as that would mean there are
809+
// more computed calls to the function than what was recorded.
810+
LLVM_DEBUG(S.F->setEntryCount(0));
811+
}
811812
}
812813
}
813814
}

0 commit comments

Comments
 (0)