[llvm] [LV] Convert scatter w/uniform addr and mask being header mask to scalar store. (PR #172799)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 5 13:50:14 PDT 2026
================
@@ -1926,8 +1926,33 @@ static void narrowToSingleScalarRecipes(VPlan &Plan) {
vp_depth_first_deep(Plan.getEntry()))) {
for (VPRecipeBase &R : make_early_inc_range(reverse(*VPBB))) {
if (!isa<VPWidenRecipe, VPWidenGEPRecipe, VPReplicateRecipe,
- VPWidenIntrinsicRecipe>(&R))
+ VPWidenIntrinsicRecipe, VPWidenStoreRecipe>(&R))
continue;
+
+ // Narrow header masked scatter to scalar store.
+ auto *WidenStoreR = dyn_cast<VPWidenStoreRecipe>(&R);
+ if (WidenStoreR) {
+ if (!vputils::isUniformAcrossVFsAndUFs(WidenStoreR->getAddr()) ||
+ WidenStoreR->isConsecutive())
+ continue;
+ VPValue *Mask = WidenStoreR->getMask();
+ if (!Mask || !vputils::isHeaderMask(Mask, Plan))
+ continue;
+
+ VPBuilder Builder(WidenStoreR);
+ VPInstruction *LastActiveLane = Builder.createLastActiveLane(Mask);
+ VPInstruction *Extract = Builder.createNaryOp(
+ VPInstruction::ExtractLane,
+ {LastActiveLane, WidenStoreR->getStoredValue()});
+ auto *ScalarStore = new VPReplicateRecipe(
+ &WidenStoreR->getIngredient(), {Extract, WidenStoreR->getAddr()},
+ /*IsSingleScalar*/ true, /*Mask*/ nullptr, {},
+ /*Metadata*/ *WidenStoreR);
+ ScalarStore->insertBefore(WidenStoreR);
----------------
fhahn wrote:
I've not looked at the test-suite diff closely, but I think there are cases where we won't be able to sink, e.g. if we have loads/stores which me alias?
https://github.com/llvm/llvm-project/pull/172799
More information about the llvm-commits
mailing list