-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[VPlan] Extract reverse operation for reverse accesses #146525
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 | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2176,6 +2176,27 @@ static VPRecipeBase *optimizeMaskToEVL(VPValue *HeaderMask, | |||||||||||||||||||||||||||||||
.Default([&](VPRecipeBase *R) { return nullptr; }); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
static void convertToEVLReverse(VPlan &Plan, VPTypeAnalysis &TypeInfo, | ||||||||||||||||||||||||||||||||
VPValue &AllOneMask, VPValue &EVL) { | ||||||||||||||||||||||||||||||||
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>( | ||||||||||||||||||||||||||||||||
vp_depth_first_shallow(Plan.getVectorLoopRegion()->getEntry()))) { | ||||||||||||||||||||||||||||||||
for (VPRecipeBase &R : make_early_inc_range(reverse(*VPBB))) { | ||||||||||||||||||||||||||||||||
auto *VPI = dyn_cast<VPInstruction>(&R); | ||||||||||||||||||||||||||||||||
if (!VPI || VPI->getOpcode() != VPInstruction::Reverse) | ||||||||||||||||||||||||||||||||
continue; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
SmallVector<VPValue *> Ops(VPI->operands()); | ||||||||||||||||||||||||||||||||
Ops.append({&AllOneMask, &EVL}); | ||||||||||||||||||||||||||||||||
auto *NewReverse = new VPWidenIntrinsicRecipe( | ||||||||||||||||||||||||||||||||
Intrinsic::experimental_vp_reverse, Ops, | ||||||||||||||||||||||||||||||||
TypeInfo.inferScalarType(VPI), VPI->getDebugLoc()); | ||||||||||||||||||||||||||||||||
Comment on lines
+2184
to
+2192
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. Minor nit, you could also use pattern matching here to avoid the dyn_cast? I'm not strongly opinionated on this though, happy to go with what you prefer
Suggested change
Comment on lines
+2184
to
+2192
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 was going to suggest we should preserve the "vp.reverse" name but then I noticed |
||||||||||||||||||||||||||||||||
NewReverse->insertBefore(VPI); | ||||||||||||||||||||||||||||||||
VPI->replaceAllUsesWith(NewReverse); | ||||||||||||||||||||||||||||||||
VPI->eraseFromParent(); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
/// Replace recipes with their EVL variants. | ||||||||||||||||||||||||||||||||
static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) { | ||||||||||||||||||||||||||||||||
Type *CanonicalIVType = Plan.getCanonicalIV()->getScalarType(); | ||||||||||||||||||||||||||||||||
|
@@ -2258,6 +2279,7 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) { | |||||||||||||||||||||||||||||||
ToErase.push_back(CurRecipe); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
convertToEVLReverse(Plan, TypeInfo, *AllOneMask, EVL); | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
for (VPRecipeBase *R : reverse(ToErase)) { | ||||||||||||||||||||||||||||||||
SmallVector<VPValue *> PossiblyDead(R->operands()); | ||||||||||||||||||||||||||||||||
|
@@ -3341,3 +3363,34 @@ void VPlanTransforms::addBranchWeightToMiddleTerminator( | |||||||||||||||||||||||||||||||
MDB.createBranchWeights({1, VectorStep - 1}, /*IsExpected=*/false); | ||||||||||||||||||||||||||||||||
MiddleTerm->addMetadata(LLVMContext::MD_prof, BranchWeights); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
void VPlanTransforms::adjustRecipesForReverseAccesses(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. I just did a quick scan and it looks like the only places where reverse is set is in This way would mean we could also remove the |
||||||||||||||||||||||||||||||||
if (Plan.hasScalarVFOnly()) | ||||||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>( | ||||||||||||||||||||||||||||||||
vp_depth_first_deep(Plan.getVectorLoopRegion()))) { | ||||||||||||||||||||||||||||||||
for (VPRecipeBase &R : *VPBB) { | ||||||||||||||||||||||||||||||||
auto *MemR = dyn_cast<VPWidenMemoryRecipe>(&R); | ||||||||||||||||||||||||||||||||
if (!MemR || !MemR->isReverse()) | ||||||||||||||||||||||||||||||||
continue; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
if (auto *L = dyn_cast<VPWidenLoadRecipe>(MemR)) { | ||||||||||||||||||||||||||||||||
auto *Reverse = | ||||||||||||||||||||||||||||||||
new VPInstruction(VPInstruction::Reverse, {L}, L->getDebugLoc()); | ||||||||||||||||||||||||||||||||
Reverse->insertAfter(L); | ||||||||||||||||||||||||||||||||
L->replaceAllUsesWith(Reverse); | ||||||||||||||||||||||||||||||||
Reverse->setOperand(0, L); | ||||||||||||||||||||||||||||||||
continue; | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
if (auto *S = dyn_cast<VPWidenStoreRecipe>(MemR)) { | ||||||||||||||||||||||||||||||||
VPValue *StoredVal = S->getStoredValue(); | ||||||||||||||||||||||||||||||||
auto *Reverse = new VPInstruction(VPInstruction::Reverse, {StoredVal}, | ||||||||||||||||||||||||||||||||
S->getDebugLoc()); | ||||||||||||||||||||||||||||||||
Reverse->insertBefore(S); | ||||||||||||||||||||||||||||||||
S->setOperand(1, Reverse); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
} |
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.
Hi, I've tried and split this out into #147868 since it looks like we can do this in the generic BasicTTIImpl costing
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.
Sure, thanks! This part of the cost model implementation is just to avoid the cost being Invalid. It definitely should be implemented as a separate patch.
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.
I think that PR is landed now, if you rebase this PR does it work without this change?