[llvm] [LV] Use vscale for tuning to improve branch weight estimates (PR #144733)

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 1 04:44:14 PDT 2025


================
@@ -7326,9 +7326,11 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
                            OrigLoop->getHeader()->getContext());
   VPlanTransforms::runPass(VPlanTransforms::replicateByVF, BestVPlan, BestVF);
   VPlanTransforms::runPass(VPlanTransforms::materializeBroadcasts, BestVPlan);
-  if (hasBranchWeightMD(*OrigLoop->getLoopLatch()->getTerminator()))
+  if (hasBranchWeightMD(*OrigLoop->getLoopLatch()->getTerminator())) {
+    std::optional<unsigned> VScale = CM.getVScaleForTuning();
     VPlanTransforms::runPass(VPlanTransforms::addBranchWeightToMiddleTerminator,
-                             BestVPlan, BestVF);
+                             BestVPlan, BestVF, VScale);
----------------
paulwalker-arm wrote:

Just to add.  It's not my intent to hold up this PR, this is more a conversation for future refactoring so we don't end up adding `VScaleForTuning` to a bunch of interfaces that don't strictly need it.

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


More information about the llvm-commits mailing list