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

Joel E. Denny via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 17 14:49:23 PDT 2025


================
@@ -746,6 +767,20 @@ 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>(RelativeBBFreq * OldEntryCount);
----------------
jdenny-ornl wrote:

Please use `round` to avoid truncation when computing `ToSubtract`.  That will avoid the 201 in the test case that should be 200.

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


More information about the llvm-commits mailing list