-
Notifications
You must be signed in to change notification settings - Fork 16.1k
[VPlan] Split out EVL exit cond transform from canonicalizeEVLLoops. NFC #178181
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
Changes from all commits
753bdde
0a49ca0
f8952aa
c0e3ae7
0edc12b
26e6cb2
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 |
|---|---|---|
|
|
@@ -3266,22 +3266,6 @@ void VPlanTransforms::canonicalizeEVLLoops(VPlan &Plan) { | |
|
|
||
| VPBasicBlock *HeaderVPBB = EVLPhi->getParent(); | ||
| VPValue *EVLIncrement = EVLPhi->getBackedgeValue(); | ||
| VPValue *AVL; | ||
| [[maybe_unused]] bool FoundAVL = | ||
| match(EVLIncrement, | ||
| m_c_Add(m_ZExtOrSelf(m_EVL(m_VPValue(AVL))), m_Specific(EVLPhi))); | ||
| assert(FoundAVL && "Didn't find AVL?"); | ||
|
|
||
| // The AVL may be capped to a safe distance. | ||
| VPValue *SafeAVL; | ||
| if (match(AVL, m_Select(m_VPValue(), m_VPValue(SafeAVL), m_VPValue()))) | ||
| AVL = SafeAVL; | ||
|
|
||
| VPValue *AVLNext; | ||
| [[maybe_unused]] bool FoundAVLNext = | ||
| match(AVL, m_VPInstruction<Instruction::PHI>( | ||
| m_Specific(Plan.getTripCount()), m_VPValue(AVLNext))); | ||
| assert(FoundAVLNext && "Didn't find AVL backedge?"); | ||
|
|
||
| // Convert EVLPhi to concrete recipe. | ||
| auto *ScalarR = | ||
|
|
@@ -3302,27 +3286,57 @@ void VPlanTransforms::canonicalizeEVLLoops(VPlan &Plan) { | |
| VPRecipeBase *CanonicalIVIncrement = Backedge->getDefiningRecipe(); | ||
| CanonicalIVIncrement->eraseFromParent(); | ||
| CanonicalIV->eraseFromParent(); | ||
| } | ||
|
|
||
| void VPlanTransforms::convertEVLExitCond(VPlan &Plan) { | ||
| VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion(); | ||
| // The canonical IV may not exist at this stage. | ||
| if (!LoopRegion || | ||
| !isa<VPCanonicalIVPHIRecipe>(LoopRegion->getEntryBasicBlock()->front())) | ||
| return; | ||
| VPCanonicalIVPHIRecipe *CanIV = LoopRegion->getCanonicalIV(); | ||
| if (std::next(CanIV->getIterator()) == CanIV->getParent()->end()) | ||
| return; | ||
| // The EVL IV is always immediately after the canonical IV. | ||
| auto *EVLPhi = | ||
| dyn_cast_or_null<VPEVLBasedIVPHIRecipe>(std::next(CanIV->getIterator())); | ||
| if (!EVLPhi) | ||
| return; | ||
|
|
||
| // Bail if not an EVL tail folded loop. | ||
| VPValue *AVL; | ||
| if (!match(EVLPhi->getBackedgeValue(), | ||
| m_c_Add(m_ZExtOrSelf(m_EVL(m_VPValue(AVL))), m_Specific(EVLPhi)))) | ||
| return; | ||
|
|
||
| // The AVL may be capped to a safe distance. | ||
| VPValue *SafeAVL; | ||
| if (match(AVL, m_Select(m_VPValue(), m_VPValue(SafeAVL), m_VPValue()))) | ||
|
Contributor
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. not related to the patch itself, but it might be good to think if we can match something more precise here, in case some transform gets applied to the original select
Contributor
Author
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. Yeah, I think we can make this more explicit. Will try to do in a follow up.
Contributor
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. Great thanks! |
||
| AVL = SafeAVL; | ||
|
|
||
| VPValue *AVLNext; | ||
| [[maybe_unused]] bool FoundAVLNext = | ||
| match(AVL, m_VPInstruction<Instruction::PHI>( | ||
| m_Specific(Plan.getTripCount()), m_VPValue(AVLNext))); | ||
| assert(FoundAVLNext && "Didn't find AVL backedge?"); | ||
|
|
||
| // Replace the use of VectorTripCount in the latch-exiting block. | ||
| // Before: (branch-on-cond (icmp eq EVLIVInc, VectorTripCount)) | ||
| // After: (branch-on-cond icmp eq AVLNext, 0) | ||
| VPBasicBlock *LatchExiting = | ||
| HeaderVPBB->getPredecessors()[1]->getEntryBasicBlock(); | ||
| auto *LatchExitingBr = cast<VPInstruction>(LatchExiting->getTerminator()); | ||
| if (match(LatchExitingBr, m_BranchOnCond(m_True()))) | ||
| VPBasicBlock *Latch = LoopRegion->getExitingBasicBlock(); | ||
| auto *LatchBr = cast<VPInstruction>(Latch->getTerminator()); | ||
| if (match(LatchBr, m_BranchOnCond(m_True()))) | ||
| return; | ||
|
|
||
| assert(match(LatchExitingBr, m_BranchOnCond(m_SpecificCmp( | ||
| CmpInst::ICMP_EQ, m_VPValue(EVLIncrement), | ||
|
Contributor
Author
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. This also fixes this m_VPValue, it should be a m_Specific |
||
| m_Specific(&Plan.getVectorTripCount())))) && | ||
| "Expected BranchOnCond with ICmp comparing EVL increment with vector " | ||
| "trip count"); | ||
| assert( | ||
| match(LatchBr, | ||
| m_BranchOnCond(m_SpecificCmp( | ||
| CmpInst::ICMP_EQ, m_Specific(CanIV->getIncomingValue(1)), | ||
| m_Specific(&Plan.getVectorTripCount())))) && | ||
| "Expected BranchOnCond with ICmp comparing CanIV increment with vector " | ||
| "trip count"); | ||
|
|
||
| Type *AVLTy = VPTypeAnalysis(Plan).inferScalarType(AVLNext); | ||
| VPBuilder Builder(LatchExitingBr); | ||
| LatchExitingBr->setOperand(0, | ||
| Builder.createICmp(CmpInst::ICMP_EQ, AVLNext, | ||
| Plan.getConstantInt(AVLTy, 0))); | ||
| VPBuilder Builder(LatchBr); | ||
| LatchBr->setOperand(0, Builder.createICmp(CmpInst::ICMP_EQ, AVLNext, | ||
| Plan.getConstantInt(AVLTy, 0))); | ||
| } | ||
|
|
||
| void VPlanTransforms::replaceSymbolicStrides( | ||
|
|
||
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 don't think we enforce the order in the verifier, so relying on it may miss some cases in the future?
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 thought we already verified this but apparently not, added in f8952aa. Maybe I had seen an assert for it somewhere else.
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.
Would be good to check how we retrieve EVL phi in other palces, possibly shairng the logic in a helper, possibly as follow-up.