-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[VPlan] Replace EVL branch condition with (branch-on-count AVLNext, 0) #152167
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 1 commit
158f82a
50ca2e5
bd2ed44
bdb8062
dc68b0b
cabb02e
428ce16
b6a82b8
f727031
4702c1d
2931aa7
e1f37f3
b24bfdb
d8b01f9
69a3ae7
13be3c8
6c7fcc4
a5d3767
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 |
|---|---|---|
|
|
@@ -740,8 +740,7 @@ static VPWidenInductionRecipe *getOptimizableIVOf(VPValue *VPV) { | |
| // IVStep will be the negated step of the subtraction. Check if Step == -1 | ||
| // * IVStep. | ||
| VPValue *Step; | ||
| if (!match(VPV, | ||
| m_Binary<Instruction::Sub>(m_VPValue(), m_VPValue(Step))) || | ||
| if (!match(VPV, m_Sub(m_VPValue(), m_VPValue(Step))) || | ||
| !Step->isLiveIn() || !IVStep->isLiveIn()) | ||
| return false; | ||
| auto *StepCI = dyn_cast<ConstantInt>(Step->getLiveInIRValue()); | ||
|
|
@@ -2386,19 +2385,38 @@ void VPlanTransforms::canonicalizeEVLLoops(VPlan &Plan) { | |
| // Find EVL loop entries by locating VPEVLBasedIVPHIRecipe. | ||
| // There should be only one EVL PHI in the entire plan. | ||
| VPEVLBasedIVPHIRecipe *EVLPhi = nullptr; | ||
| VPValue *AVLNext = nullptr; | ||
|
|
||
| for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>( | ||
| vp_depth_first_shallow(Plan.getEntry()))) | ||
| for (VPRecipeBase &R : VPBB->phis()) | ||
| if (auto *PhiR = dyn_cast<VPEVLBasedIVPHIRecipe>(&R)) { | ||
| for (VPRecipeBase &R : VPBB->phis()) { | ||
| auto *PhiR = dyn_cast<VPSingleDefRecipe>(&R); | ||
lukel97 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (!PhiR) | ||
| continue; | ||
| VPValue *Backedge; | ||
| if (auto *EVL = dyn_cast<VPEVLBasedIVPHIRecipe>(PhiR)) { | ||
| assert(!EVLPhi && "Found multiple EVL PHIs. Only one expected"); | ||
| EVLPhi = PhiR; | ||
| EVLPhi = EVL; | ||
| continue; | ||
| } | ||
| if (match(PhiR, | ||
| m_Phi(m_Specific(Plan.getTripCount()), m_VPValue(Backedge))) && | ||
| match(Backedge, m_Sub(m_Specific(PhiR), | ||
| m_ZExtOrSelf(m_ExplicitVectorLength(m_CombineOr( | ||
| m_Specific(PhiR), | ||
| // The AVL may be capped to a safe distance. | ||
| m_Select(m_VPValue(), m_Specific(PhiR), | ||
| m_VPValue()))))))) { | ||
| AVLNext = Backedge; | ||
| } | ||
| } | ||
|
|
||
| // Early return if no EVL PHI is found. | ||
| if (!EVLPhi) | ||
| return; | ||
|
|
||
| assert(AVLNext && "Didn't find AVL backedge?"); | ||
|
|
||
| VPBasicBlock *HeaderVPBB = EVLPhi->getParent(); | ||
| VPValue *EVLIncrement = EVLPhi->getBackedgeValue(); | ||
|
|
||
|
|
@@ -2425,7 +2443,7 @@ void VPlanTransforms::canonicalizeEVLLoops(VPlan &Plan) { | |
|
|
||
| // Replace the use of VectorTripCount in the latch-exiting block. | ||
| // Before: (branch-on-count EVLIVInc, VectorTripCount) | ||
| // After: (branch-on-count EVLIVInc, TripCount) | ||
| // After: (branch-on-count AVLNext, 0) | ||
|
||
|
|
||
| VPBasicBlock *LatchExiting = | ||
| HeaderVPBB->getPredecessors()[1]->getEntryBasicBlock(); | ||
|
|
@@ -2438,7 +2456,12 @@ void VPlanTransforms::canonicalizeEVLLoops(VPlan &Plan) { | |
| m_BranchOnCount(m_VPValue(EVLIncrement), | ||
| m_Specific(&Plan.getVectorTripCount()))) && | ||
| "Unexpected terminator in EVL loop"); | ||
| LatchExitingBr->setOperand(1, Plan.getTripCount()); | ||
|
|
||
| Type *AVLTy = VPTypeAnalysis(Plan).inferScalarType(AVLNext); | ||
|
|
||
| LatchExitingBr->setOperand(0, AVLNext); | ||
| LatchExitingBr->setOperand( | ||
| 1, Plan.getOrAddLiveIn(ConstantInt::getNullValue(AVLTy))); | ||
| } | ||
|
|
||
| void VPlanTransforms::dropPoisonGeneratingRecipes( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -216,9 +216,10 @@ struct VPlanTransforms { | |
| /// variable vector lengths instead of fixed lengths. This transformation: | ||
| /// * Makes EVL-Phi concrete. | ||
| // * Removes CanonicalIV and increment. | ||
| /// * Replaces fixed-length stepping (branch-on-cond CanonicalIVInc, | ||
| /// VectorTripCount) with variable-length stepping (branch-on-cond | ||
| /// EVLIVInc, TripCount). | ||
| /// * Replaces the exit condition from | ||
| /// (branch-on-cond CanonicalIVInc, VectorTripCount) | ||
| /// to | ||
| /// (branch-on-cond AVLNext, 0) | ||
|
||
| static void canonicalizeEVLLoops(VPlan &Plan); | ||
|
|
||
| /// Lower abstract recipes to concrete ones, that can be codegen'd. Use \p | ||
|
|
||
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 these changes must be in a separate NFC 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've taken out all but the necessary pattern match changes in 50ca2e5, will open up separate PRs afterwards to tidy up