-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[VPlan] Iterate over header phis to determine FORs that need EVL fixup. NFCI #147032
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 1 commit
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 | ||||
---|---|---|---|---|---|---|
|
@@ -2187,42 +2187,48 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) { | |||||
// VPTypeAnalysis cache. | ||||||
SmallVector<VPRecipeBase *> ToErase; | ||||||
|
||||||
// Create a scalar phi to track the previous EVL if fixed-order recurrence is | ||||||
// contained. | ||||||
bool ContainsFORs = | ||||||
any_of(Header->phis(), IsaPred<VPFirstOrderRecurrencePHIRecipe>); | ||||||
if (ContainsFORs) { | ||||||
// TODO: Use VPInstruction::ExplicitVectorLength to get maximum EVL. | ||||||
VPValue *MaxEVL = &Plan.getVF(); | ||||||
// Emit VPScalarCastRecipe in preheader if VF is not a 32 bits integer. | ||||||
VPBuilder Builder(LoopRegion->getPreheaderVPBB()); | ||||||
MaxEVL = Builder.createScalarZExtOrTrunc(MaxEVL, Type::getInt32Ty(Ctx), | ||||||
TypeInfo.inferScalarType(MaxEVL), | ||||||
DebugLoc()); | ||||||
|
||||||
Builder.setInsertPoint(Header, Header->getFirstNonPhi()); | ||||||
VPValue *PrevEVL = | ||||||
Builder.createScalarPhi({MaxEVL, &EVL}, DebugLoc(), "prev.evl"); | ||||||
|
||||||
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>( | ||||||
vp_depth_first_deep(Plan.getVectorLoopRegion()->getEntry()))) { | ||||||
for (VPRecipeBase &R : *VPBB) { | ||||||
using namespace VPlanPatternMatch; | ||||||
VPValue *V1, *V2; | ||||||
if (!match(&R, | ||||||
m_VPInstruction<VPInstruction::FirstOrderRecurrenceSplice>( | ||||||
m_VPValue(V1), m_VPValue(V2)))) | ||||||
continue; | ||||||
VPValue *Imm = Plan.getOrAddLiveIn( | ||||||
ConstantInt::getSigned(Type::getInt32Ty(Ctx), -1)); | ||||||
VPWidenIntrinsicRecipe *VPSplice = new VPWidenIntrinsicRecipe( | ||||||
Intrinsic::experimental_vp_splice, | ||||||
{V1, V2, Imm, AllOneMask, PrevEVL, &EVL}, | ||||||
TypeInfo.inferScalarType(R.getVPSingleValue()), R.getDebugLoc()); | ||||||
VPSplice->insertBefore(&R); | ||||||
R.getVPSingleValue()->replaceAllUsesWith(VPSplice); | ||||||
ToErase.push_back(&R); | ||||||
} | ||||||
// Fix-up first-order recurrences | ||||||
VPValue *PrevEVL = nullptr; | ||||||
for (VPRecipeBase &PhiR : Header->phis()) { | ||||||
auto *FOR = dyn_cast<VPFirstOrderRecurrencePHIRecipe>(&PhiR); | ||||||
if (!FOR) | ||||||
continue; | ||||||
|
||||||
// Create a scalar phi to track the previous EVL if fixed-order recurrence | ||||||
// is contained. | ||||||
if (!PrevEVL) { | ||||||
// TODO: Use VPInstruction::ExplicitVectorLength to get maximum EVL. | ||||||
VPValue *MaxEVL = &Plan.getVF(); | ||||||
// Emit VPScalarCastRecipe in preheader if VF is not a 32 bits integer. | ||||||
VPBuilder Builder(LoopRegion->getPreheaderVPBB()); | ||||||
MaxEVL = Builder.createScalarZExtOrTrunc(MaxEVL, Type::getInt32Ty(Ctx), | ||||||
TypeInfo.inferScalarType(MaxEVL), | ||||||
DebugLoc()); | ||||||
|
||||||
Builder.setInsertPoint(Header, Header->getFirstNonPhi()); | ||||||
PrevEVL = Builder.createScalarPhi({MaxEVL, &EVL}, DebugLoc(), "prev.evl"); | ||||||
} | ||||||
|
||||||
assert(!Plan.isUnrolled() && "When unrolled splices might not use " | ||||||
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. can move assert either to just after early continue in loop or even before the loop? |
||||||
"VPFirstOrederRecurrencePHIRecipe!"); | ||||||
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
|
||||||
|
||||||
for (VPUser *User : PhiR.getVPSingleValue()->users()) { | ||||||
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 *R = cast<VPRecipeBase>(User); | ||||||
using namespace VPlanPatternMatch; | ||||||
VPValue *V1, *V2; | ||||||
if (!match(R, m_VPInstruction<VPInstruction::FirstOrderRecurrenceSplice>( | ||||||
m_VPValue(V1), m_VPValue(V2)))) | ||||||
continue; | ||||||
VPValue *Imm = Plan.getOrAddLiveIn( | ||||||
ConstantInt::getSigned(Type::getInt32Ty(Ctx), -1)); | ||||||
VPWidenIntrinsicRecipe *VPSplice = new VPWidenIntrinsicRecipe( | ||||||
Intrinsic::experimental_vp_splice, | ||||||
{V1, V2, Imm, AllOneMask, PrevEVL, &EVL}, | ||||||
TypeInfo.inferScalarType(R->getVPSingleValue()), R->getDebugLoc()); | ||||||
|
||||||
VPSplice->insertBefore(R); | ||||||
R->getVPSingleValue()->replaceAllUsesWith(VPSplice); | ||||||
ToErase.push_back(R); | ||||||
} | ||||||
} | ||||||
|
||||||
|
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.