[llvm] [VPlan] Use BlockFrequencyInfo in getPredBlockCostDivisor (PR #158690)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 25 04:15:26 PST 2025
================
@@ -2886,6 +2884,23 @@ bool LoopVectorizationCostModel::isPredicatedInst(Instruction *I) const {
}
}
+unsigned LoopVectorizationCostModel::getPredBlockCostDivisor(
+ TargetTransformInfo::TargetCostKind CostKind, const BasicBlock *BB) const {
+ // If the block wasn't originally predicated then return early to avoid
+ // computing BlockFrequencyInfo unnecessarily.
+ if (!Legal->blockNeedsPredication(BB))
+ return 1;
+ if (CostKind == TTI::TCK_CodeSize)
+ return 1;
+
+ BlockFrequencyInfo *BFI = GetBFI();
+ uint64_t HeaderFreq = BFI->getBlockFreq(TheLoop->getHeader()).getFrequency();
+ uint64_t BBFreq = BFI->getBlockFreq(BB).getFrequency();
+ assert(HeaderFreq >= BBFreq &&
+ "Header has smaller block freq than dominated BB?");
+ return HeaderFreq / BBFreq;
----------------
lukel97 wrote:
Exactly, as an aside I added that assert in because when I first started this PR there was a bug with the pass manager that meant the header sometimes had a smaller frequency, which led to divisions by zero. It was fixed in 4663d2521c65827ca22884e12a96ddd437377e31
https://github.com/llvm/llvm-project/pull/158690
More information about the llvm-commits
mailing list