-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[VPlan] Extract reverse mask from reverse accesses #155579
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
7b22b76
4b0798f
66c7081
72d3bc6
d33737e
a9d4ab0
61f053d
69053f5
715a55f
7c2493d
53be850
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 |
---|---|---|
|
@@ -6939,6 +6939,29 @@ static bool planContainsAdditionalSimplifications(VPlan &Plan, | |
cast<VPRecipeWithIRFlags>(R).getPredicate() != | ||
cast<CmpInst>(UI)->getPredicate()) | ||
return true; | ||
|
||
if (auto *MemR = dyn_cast<VPWidenMemoryRecipe>(&R)) { | ||
bool IsReverse = CostCtx.CM.getWideningDecision(UI, VF) == | ||
LoopVectorizationCostModel::CM_Widen_Reverse; | ||
if (IsReverse) { | ||
// The legacy model have not computed the cost of reverse mask. | ||
if (CostCtx.CM.Legal->isMaskRequired(UI)) | ||
return true; | ||
|
||
|
||
// If the stored value of a reverse store is invariant, LICM will | ||
// hoist the reverse operation to the preheader. In this case, the | ||
// result of the VPlan-based cost model will diverge from that of | ||
// the legacy model. | ||
if (auto *StoreR = dyn_cast<VPWidenStoreRecipe>(MemR)) | ||
if (StoreR->getStoredValue()->isDefinedOutsideLoopRegions()) | ||
return true; | ||
|
||
if (auto *StoreR = dyn_cast<VPWidenStoreEVLRecipe>(MemR)) | ||
if (StoreR->getStoredValue()->isDefinedOutsideLoopRegions()) | ||
return true; | ||
} | ||
} | ||
|
||
SeenInstrs.insert(UI); | ||
} | ||
} | ||
|
@@ -7608,9 +7631,9 @@ void EpilogueVectorizerEpilogueLoop::printDebugTracesAtEnd() { | |
}); | ||
} | ||
|
||
VPWidenMemoryRecipe * | ||
VPRecipeBuilder::tryToWidenMemory(Instruction *I, ArrayRef<VPValue *> Operands, | ||
VFRange &Range) { | ||
VPRecipeBase *VPRecipeBuilder::tryToWidenMemory(Instruction *I, | ||
ArrayRef<VPValue *> Operands, | ||
VFRange &Range) { | ||
assert((isa<LoadInst>(I) || isa<StoreInst>(I)) && | ||
"Must be called with either a load or store"); | ||
|
||
|
@@ -7667,14 +7690,30 @@ VPRecipeBuilder::tryToWidenMemory(Instruction *I, ArrayRef<VPValue *> Operands, | |
Builder.insert(VectorPtr); | ||
Ptr = VectorPtr; | ||
} | ||
if (LoadInst *Load = dyn_cast<LoadInst>(I)) | ||
return new VPWidenLoadRecipe(*Load, Ptr, Mask, Consecutive, Reverse, | ||
VPIRMetadata(*Load, LVer), I->getDebugLoc()); | ||
|
||
StoreInst *Store = cast<StoreInst>(I); | ||
return new VPWidenStoreRecipe(*Store, Ptr, Operands[0], Mask, Consecutive, | ||
Reverse, VPIRMetadata(*Store, LVer), | ||
I->getDebugLoc()); | ||
if (Reverse && Mask) | ||
Mask = Builder.createNaryOp(VPInstruction::Reverse, Mask, I->getDebugLoc()); | ||
|
||
if (auto *Load = dyn_cast<LoadInst>(I)) { | ||
auto *LoadR = | ||
new VPWidenLoadRecipe(*Load, Ptr, Mask, Consecutive, | ||
VPIRMetadata(*Load, LVer), Load->getDebugLoc()); | ||
if (Reverse) { | ||
Builder.insert(LoadR); | ||
return new VPInstruction(VPInstruction::Reverse, {LoadR}, | ||
LoadR->getDebugLoc()); | ||
} | ||
return LoadR; | ||
} | ||
|
||
auto *Store = cast<StoreInst>(I); | ||
VPValue *StoredVal = Operands[0]; | ||
if (Reverse) | ||
StoredVal = Builder.createNaryOp(VPInstruction::Reverse, StoredVal, | ||
Store->getDebugLoc()); | ||
return new VPWidenStoreRecipe(*Store, Ptr, StoredVal, Mask, Consecutive, | ||
VPIRMetadata(*Store, LVer), | ||
Store->getDebugLoc()); | ||
} | ||
|
||
/// Creates a VPWidenIntOrFpInductionRecpipe for \p Phi. If needed, it will also | ||
|
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.
#146525 (comment)
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.
@fhahn I think this is the most straightforward approach.
Currently, we could check whether the operand or user is a reverse operation, but in the future reverse operations might be simplified away, so relying on reverse operation is not a long-term approach.
The last option is to use the address for the check, since only reverse operations need to use VPVectorEndPointer.
What do you think?