Skip to content

Commit 6acdd6c

Browse files
committed
code review comments
1 parent 4ca46c3 commit 6acdd6c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

llvm/lib/Transforms/IPO/FunctionSpecialization.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -788,18 +788,23 @@ bool FunctionSpecializer::run() {
788788
LLVM_DEBUG(dbgs() << "FnSpecialization: Redirecting " << *Call
789789
<< " to call " << Clone->getName() << "\n");
790790
Call->setCalledFunction(S.Clone);
791+
auto &BFI = GetBFI(*Call->getFunction());
791792
if (std::optional<uint64_t> Count =
792-
GetBFI(*Call->getFunction())
793-
.getBlockProfileCount(Call->getParent())) {
794-
uint64_t CallCount = *Count + Clone->getEntryCount()->getCount();
793+
BFI.getBlockProfileCount(Call->getParent())) {
794+
std::optional<llvm::Function::ProfileCount> MaybeCloneCount =
795+
Clone->getEntryCount();
796+
assert(MaybeCloneCount && "Clone entry count was not set!");
797+
uint64_t CallCount = *Count + MaybeCloneCount->getCount();
795798
Clone->setEntryCount(CallCount);
796799
if (std::optional<llvm::Function::ProfileCount> MaybeOriginalCount =
797800
S.F->getEntryCount()) {
798801
uint64_t OriginalCount = MaybeOriginalCount->getCount();
799-
if (OriginalCount > CallCount) {
802+
if (OriginalCount >= CallCount) {
800803
S.F->setEntryCount(OriginalCount - CallCount);
801804
} else {
802-
S.F->setEntryCount(0);
805+
// This should generally not happen as that would mean there are
806+
// more computed calls to the function than what was recorded.
807+
LLVM_DEBUG(S.F->setEntryCount(0));
803808
}
804809
}
805810
}

0 commit comments

Comments
 (0)