-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[VPlan] Simplify ExplicitVectorLength(%AVL) -> %AVL when AVL <= VF #167647
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
f8a80b1
6bb2fe0
a4aa19e
027c462
fa1844c
8580c7d
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 |
|---|---|---|
|
|
@@ -1843,6 +1843,35 @@ static bool simplifyBranchConditionForVFAndUF(VPlan &Plan, ElementCount BestVF, | |
| return true; | ||
| } | ||
|
|
||
| /// From the definition of llvm.experimental.get.vector.length, | ||
| /// VPInstruction::ExplicitVectorLength(%AVL) = %AVL when %AVL <= VF. | ||
| static bool simplifyKnownEVL(VPlan &Plan, ElementCount VF, | ||
| PredicatedScalarEvolution &PSE) { | ||
| for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>( | ||
| vp_depth_first_deep(Plan.getEntry()))) { | ||
| for (VPRecipeBase &R : *VPBB) { | ||
| VPValue *AVL; | ||
| if (!match(&R, m_EVL(m_VPValue(AVL)))) | ||
| continue; | ||
|
|
||
| ScalarEvolution &SE = *PSE.getSE(); | ||
| const SCEV *AVLSCEV = vputils::getSCEVExprForVPValue(AVL, SE); | ||
| if (isa<SCEVCouldNotCompute>(AVLSCEV)) | ||
| continue; | ||
| const SCEV *VFSCEV = SE.getElementCount(AVLSCEV->getType(), VF); | ||
| if (!SE.isKnownPredicate(CmpInst::ICMP_ULE, AVLSCEV, VFSCEV)) | ||
| continue; | ||
|
|
||
| VPValue *Trunc = VPBuilder(&R).createScalarZExtOrTrunc( | ||
| AVL, Type::getInt32Ty(Plan.getContext()), AVLSCEV->getType(), | ||
| R.getDebugLoc()); | ||
| R.getVPSingleValue()->replaceAllUsesWith(Trunc); | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| void VPlanTransforms::optimizeForVFAndUF(VPlan &Plan, ElementCount BestVF, | ||
| unsigned BestUF, | ||
| PredicatedScalarEvolution &PSE) { | ||
|
|
@@ -1852,6 +1881,7 @@ void VPlanTransforms::optimizeForVFAndUF(VPlan &Plan, ElementCount BestVF, | |
| bool MadeChange = tryToReplaceALMWithWideALM(Plan, BestVF, BestUF); | ||
| MadeChange |= simplifyBranchConditionForVFAndUF(Plan, BestVF, BestUF, PSE); | ||
| MadeChange |= optimizeVectorInductionWidthForTCAndVFUF(Plan, BestVF, BestUF); | ||
| MadeChange |= simplifyKnownEVL(Plan, BestVF, PSE); | ||
|
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. If we move this to the start, would it be sufficient to do a shallow traversal starting at the region entry?
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. I think this needs to run after simplifyBranchConditionForVFAndUF so that the AVL PHI feeding into ExplicitVectorLength is replaced with its singular incoming value, and it looks like the region is removed there
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. ah that's unfortuante, thanks for checking |
||
|
|
||
| if (MadeChange) { | ||
| Plan.setVF(BestVF); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.