[llvm] [TRE] Adjust function entry count when using instrumented profiles (PR #143987)
Alexey Lapshin via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 18 13:59:29 PDT 2025
================
@@ -735,6 +757,21 @@ bool TailRecursionEliminator::eliminateCall(CallInst *CI) {
CI->eraseFromParent(); // Remove call.
DTU.applyUpdates({{DominatorTree::Insert, BB, HeaderBB}});
++NumEliminated;
+ if (OrigEntryBBFreq) {
+ assert(F.getEntryCount().has_value());
+ // This pass is not expected to remove BBs, only add an entry BB. For that
+ // reason, and because the BB here isn't the new entry BB, the BFI lookup is
+ // expected to succeed.
+ assert(&F.getEntryBlock() != BB);
+ auto RelativeBBFreq =
+ static_cast<double>(BFI->getBlockFreq(BB).getFrequency()) /
+ static_cast<double>(OrigEntryBBFreq);
+ auto OldEntryCount = F.getEntryCount()->getCount();
+ auto ToSubtract =
+ static_cast<uint64_t>(std::round(RelativeBBFreq * OldEntryCount));
+ assert(OldEntryCount > ToSubtract);
----------------
avl-llvm wrote:
it looks like checking values before use and reporting bad case using LLVM_DEBUG would be good enough.
https://github.com/llvm/llvm-project/pull/143987
More information about the llvm-commits
mailing list