[llvm] LoopVectorize: Use a better heuristic for epilogue branch weights (PR #72589)
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 17 11:47:39 PST 2023
================
@@ -8079,8 +8075,16 @@ EpilogueVectorizerEpilogueLoop::emitMinimumVectorEpilogueIterCountCheck(
BranchInst &BI =
*BranchInst::Create(Bypass, LoopVectorPreHeader, CheckMinIters);
- if (hasBranchWeightMD(*OrigLoop->getLoopLatch()->getTerminator()))
- setBranchWeights(BI, EpilogueMinItersBypassWeights);
+ if (hasBranchWeightMD(*OrigLoop->getLoopLatch()->getTerminator())) {
+ // Assume the tripcount for the epilogue loop is equally distributed between
+ // 0 and `VectorTripCount - 1` leaving us with a `VectorTripCount * 0.5`
+ // branch weight.
+ unsigned CombinedFactor = UF * VF.getKnownMinValue();
+ assert(CombinedFactor > 1 && "UF times VF should be bigger than one");
+ unsigned EstimatedTripCount = (CombinedFactor + 1) / 2;
+ uint32_t Weights[] = {1, EstimatedTripCount};
----------------
MatzeB wrote:
Thanks for catching this!
https://github.com/llvm/llvm-project/pull/72589
More information about the llvm-commits
mailing list