-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[LV] Convert uniform-address scatters to scalar store when unmasked or header-masked. #166114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1372,6 +1372,50 @@ void VPlanTransforms::simplifyRecipes(VPlan &Plan) { | |||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| static VPSingleDefRecipe *findHeaderMask(VPlan &Plan); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// Convert scatters with a uniform address that are either unmasked or | ||||||||||||||||||||||
| /// masked by the header mask into an extract-last-element + scalar store. | ||||||||||||||||||||||
| // TODO: Add a profitability check comparing the cost of a scatter vs. | ||||||||||||||||||||||
| // extract + scalar store. | ||||||||||||||||||||||
| static void optimizeScatterWithUniformAddr(VPlan &Plan) { | ||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason this cannot be handled in |
||||||||||||||||||||||
| VPValue *HeaderMask = findHeaderMask(Plan); | ||||||||||||||||||||||
| for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>( | ||||||||||||||||||||||
| vp_depth_first_deep(Plan.getEntry()))) { | ||||||||||||||||||||||
| for (VPRecipeBase &R : make_early_inc_range(*VPBB)) { | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Only transform store recipes. | ||||||||||||||||||||||
| if (!isa<VPWidenStoreRecipe, VPWidenStoreEVLRecipe>(&R)) | ||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we only can handle VPWidenStoreRecipe before @fhahn's LastActiveLane patch is landed. |
||||||||||||||||||||||
| continue; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| auto StoreR = cast<VPWidenMemoryRecipe>(&R); | ||||||||||||||||||||||
| if (StoreR->isConsecutive() || | ||||||||||||||||||||||
| !vputils::isSingleScalar(StoreR->getAddr())) | ||||||||||||||||||||||
| continue; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| assert(!StoreR->isReverse() && | ||||||||||||||||||||||
| "Not consecutive memory recipes shouldn't be reversed"); | ||||||||||||||||||||||
| VPValue *Mask = StoreR->getMask(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Only convert the scatter to a scalar store if it is unmasked or masked | ||||||||||||||||||||||
| // by the header mask, which guarantees that at least one active lane. | ||||||||||||||||||||||
| if (Mask && Mask != HeaderMask) | ||||||||||||||||||||||
| continue; | ||||||||||||||||||||||
|
Comment on lines
+1398
to
+1403
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| auto *Extract = new VPInstruction(VPInstruction::ExtractLastElement, | ||||||||||||||||||||||
| {StoreR->getOperand(1)}); | ||||||||||||||||||||||
| Extract->insertBefore(StoreR); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // TODO: Sink the scalar store recipe to middle block if possible. | ||||||||||||||||||||||
| auto *ScalarStore = new VPReplicateRecipe( | ||||||||||||||||||||||
| &StoreR->getIngredient(), {Extract, StoreR->getAddr()}, | ||||||||||||||||||||||
| true /*IsSingleScalar*/, nullptr /*Mask*/, *StoreR /*Metadata*/); | ||||||||||||||||||||||
| ScalarStore->insertBefore(StoreR); | ||||||||||||||||||||||
| StoreR->eraseFromParent(); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| static void narrowToSingleScalarRecipes(VPlan &Plan) { | ||||||||||||||||||||||
| if (Plan.hasScalarVFOnly()) | ||||||||||||||||||||||
| return; | ||||||||||||||||||||||
|
|
@@ -2320,6 +2364,7 @@ void VPlanTransforms::optimize(VPlan &Plan) { | |||||||||||||||||||||
| runPass(removeDeadRecipes, Plan); | ||||||||||||||||||||||
| runPass(simplifyBlends, Plan); | ||||||||||||||||||||||
| runPass(legalizeAndOptimizeInductions, Plan); | ||||||||||||||||||||||
| runPass(optimizeScatterWithUniformAddr, Plan); | ||||||||||||||||||||||
| runPass(narrowToSingleScalarRecipes, Plan); | ||||||||||||||||||||||
| runPass(removeRedundantExpandSCEVRecipes, Plan); | ||||||||||||||||||||||
| runPass(simplifyRecipes, Plan); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?