-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[VPlan] Replace BranchOnCount with Compare + BranchOnCond (NFC). #172181
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
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3201,27 +3201,25 @@ void VPlanTransforms::canonicalizeEVLLoops(VPlan &Plan) { | |||||
| CanonicalIV->eraseFromParent(); | ||||||
|
|
||||||
| // Replace the use of VectorTripCount in the latch-exiting block. | ||||||
| // Before: (branch-on-count EVLIVInc, VectorTripCount) | ||||||
| // After: (branch-on-cond eq AVLNext, 0) | ||||||
|
|
||||||
| // 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()); | ||||||
| // Skip single-iteration loop region | ||||||
| if (match(LatchExitingBr, m_BranchOnCond(m_True()))) | ||||||
| return; | ||||||
| assert(LatchExitingBr && | ||||||
| match(LatchExitingBr, | ||||||
| m_BranchOnCount(m_VPValue(EVLIncrement), | ||||||
| m_Specific(&Plan.getVectorTripCount()))) && | ||||||
| "Unexpected terminator in EVL loop"); | ||||||
|
|
||||||
| assert(match(LatchExitingBr, m_BranchOnCond(m_SpecificCmp( | ||||||
| CmpInst::ICMP_EQ, m_VPValue(EVLIncrement), | ||||||
| m_Specific(&Plan.getVectorTripCount())))) && | ||||||
| "Expected BranchOnCond with ICmp comparing EVL increment with vector " | ||||||
| "trip count"); | ||||||
|
|
||||||
| Type *AVLTy = VPTypeAnalysis(Plan).inferScalarType(AVLNext); | ||||||
| VPBuilder Builder(LatchExitingBr); | ||||||
| VPValue *Cmp = Builder.createICmp(CmpInst::ICMP_EQ, AVLNext, | ||||||
| Plan.getConstantInt(AVLTy, 0)); | ||||||
| Builder.createNaryOp(VPInstruction::BranchOnCond, Cmp); | ||||||
| LatchExitingBr->eraseFromParent(); | ||||||
| LatchExitingBr->setOperand(0, | ||||||
| Builder.createICmp(CmpInst::ICMP_EQ, AVLNext, | ||||||
| Plan.getConstantInt(AVLTy, 0))); | ||||||
|
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. I think this will leave behind a potentially dead icmp but that should be ok since we run removeDeadRecipes afterwards? |
||||||
| } | ||||||
|
|
||||||
| void VPlanTransforms::replaceSymbolicStrides( | ||||||
|
|
@@ -3740,6 +3738,17 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan) { | |||||
| continue; | ||||||
| } | ||||||
|
|
||||||
| // Lower BranchOnCount to ICmp + BranchOnCond. | ||||||
| VPValue *IV, *TC; | ||||||
| if (match(&R, m_BranchOnCount(m_VPValue(IV), m_VPValue(TC)))) { | ||||||
| auto *BranchOnCountInst = cast<VPInstruction>(&R); | ||||||
| DebugLoc DL = BranchOnCountInst->getDebugLoc(); | ||||||
| VPValue *Cond = Builder.createICmp(CmpInst::ICMP_EQ, IV, TC, DL); | ||||||
| Builder.createNaryOp(VPInstruction::BranchOnCond, {Cond}, DL); | ||||||
|
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. Does the singleton constructor work?
Suggested change
|
||||||
| ToRemove.push_back(BranchOnCountInst); | ||||||
| continue; | ||||||
| } | ||||||
|
|
||||||
| VPValue *VectorStep; | ||||||
| VPValue *ScalarStep; | ||||||
| if (!match(&R, m_VPInstruction<VPInstruction::WideIVStep>( | ||||||
|
|
@@ -3853,6 +3862,7 @@ void VPlanTransforms::handleUncountableEarlyExit(VPBasicBlock *EarlyExitingVPBB, | |||||
| // with one exiting if either the original condition of the vector latch is | ||||||
| // true or the early exit has been taken. | ||||||
| auto *LatchExitingBranch = cast<VPInstruction>(LatchVPBB->getTerminator()); | ||||||
| // Skip single-iteration loop region | ||||||
| assert(LatchExitingBranch->getOpcode() == VPInstruction::BranchOnCount && | ||||||
| "Unexpected terminator"); | ||||||
| auto *IsLatchExitTaken = | ||||||
|
|
||||||
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.
Does the "Second successor may be backwards - iff it is already in VPBB2IRBB." comment still hold?