[llvm] [TRE] Adjust function entry count when using instrumented profiles (PR #143987)

Joel E. Denny via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 20 10:39:02 PDT 2025


================
@@ -735,6 +756,28 @@ 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();
----------------
jdenny-ornl wrote:

When multiple tail calls in a function are processed (as in the new test function `test_multiple_blocks_entry_count`), after the first tail call is processed, `OldEntryCount` here is the modified function entry count not the original.  That accumulates error in the new function entry count.

https://github.com/llvm/llvm-project/pull/143987


More information about the llvm-commits mailing list