[llvm] [LV] Convert scatter w/uniform addr and mask being header mask to scalar store. (PR #172799)

Elvis Wang via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 27 00:24:57 PDT 2026


================
@@ -7676,19 +7676,32 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
     VFRange SubRange = {VF, MaxVFTimes2};
     if (auto Plan = tryToBuildVPlanWithVPRecipes(
             std::unique_ptr<VPlan>(VPlan0->duplicate()), SubRange, &LVer)) {
+      // Add the start VF to prevent optimizations on plan with scalar VF.
+      Plan->addVF(SubRange.Start);
+      Plan->setName("Initial VPlan");
+
       // Now optimize the initial VPlan.
       VPlanTransforms::hoistPredicatedLoads(*Plan, PSE, OrigLoop);
       VPlanTransforms::sinkPredicatedStores(*Plan, PSE, OrigLoop);
       RUN_VPLAN_PASS(VPlanTransforms::truncateToMinimalBitwidths, *Plan,
                      CM.getMinimalBitwidths());
       RUN_VPLAN_PASS(VPlanTransforms::optimize, *Plan);
+      VPCostContext CostCtx(CM.TTI, *CM.TLI, *Plan, CM, CM.CostKind, CM.PSE,
+                            OrigLoop);
+      // TODO: Try to put narrowScatters in VPlanTransforms::optimize
+      RUN_VPLAN_PASS(VPlanTransforms::narrowScatters, *Plan, CostCtx, SubRange,
+                     CM.foldTailWithEVL());
----------------
ElvisWang123 wrote:

Put this pass after optimize pipeline can expose more opportunity of scatters that can converts to the scalar store. 
I've tested long time ago that if putting this pass before optimize, some loops won't be optimized.

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


More information about the llvm-commits mailing list