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

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 1 00:17:03 PDT 2026


================
@@ -6826,6 +6824,12 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlan(VPlanPtr Plan,
   if (Range.Start.isScalar())
     Range.End = Range.Start * 2;
 
+  RUN_VPLAN_PASS(VPlanTransforms::truncateToMinimalBitwidths, *Plan,
+                 Config.getMinimalBitwidths(), Range);
+  RUN_VPLAN_PASS(VPlanTransforms::simplifyRecipes, *Plan);
+  RUN_VPLAN_PASS(VPlanTransforms::narrowScatters, *Plan, CostCtx, Range,
+                 CM->foldTailWithEVL());
----------------
lukel97 wrote:

I would really like to avoid having to pass the legacy cost model here.

I'm still not 100% sure that this should be cost modelled, especially since most of the time the extract and store will be sunk to the middle block.  

vector->scalar extracts are expensive on RISC-V and the cost model increased recently in #214481. And after looking at this more closely I'm not sure if we will actually want to scalarize these if they can't be sunk. Using https://camel-cdr.github.io/rvv-bench-results/spacemit_x100/index.html as a reference, we'll need at least a vslidedown.vx + vmv.s.x which has a recip throughput of 5 + 6 = 11 cycles at LMUL 2. A vector store with e8 elements (worst case) has a recip throughput of only 6 cycles. 

Can we instead restrict this transform so that it only narrows scatters whenever it's safe to sink to the middle block? That way we can do this without a cost model as it should be universally profitable to move it out of the vector body.

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


More information about the llvm-commits mailing list