[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 09:16:00 PDT 2025


================
@@ -428,8 +438,19 @@ class TailRecursionEliminator {
 
   TailRecursionEliminator(Function &F, const TargetTransformInfo *TTI,
                           AliasAnalysis *AA, OptimizationRemarkEmitter *ORE,
-                          DomTreeUpdater &DTU)
-      : F(F), TTI(TTI), AA(AA), ORE(ORE), DTU(DTU) {}
+                          DomTreeUpdater &DTU, BlockFrequencyInfo *BFI)
+      : F(F), TTI(TTI), AA(AA), ORE(ORE), DTU(DTU), BFI(BFI),
+        OrigEntryBBFreq(
+            BFI ? BFI->getBlockFreq(&F.getEntryBlock()).getFrequency() : 0U) {
+    if (BFI) {
+      auto EC = F.getEntryCount();
+      (void)EC;
+      assert((EC.has_value() && EC->getCount() != 0 && OrigEntryBBFreq) &&
----------------
jdenny-ornl wrote:

```suggestion
      assert((EC.has_value() && EC->getCount() != 0 && OrigEntryBBFreq != 0) &&
```

For consistency.

Also, is it the caller of the ctor that is required to ensure this assert is not violated, or is it a more general constraint somehow?  If the former, can we have a brief comment saying so?  That is, as far as I can tell, this assert is guaranteed because (1) `TailCallElimPass::run` ensures that BFI is `nullptr` when `EC.has_value() && EC->getCount() != 0` here is false and (2) `TailCallElim::runOnFunction` sets BFI to `nullptr` always.

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


More information about the llvm-commits mailing list