[llvm] [VPlan] Update scalar induction resume values in VPlan. (PR #110577)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 5 14:56:39 PST 2024
================
@@ -2652,26 +2673,27 @@ static Value *getExpandedStep(const InductionDescriptor &ID,
return I->second;
}
-void InnerLoopVectorizer::createInductionResumeValues(
- const SCEV2ValueTy &ExpandedSCEVs,
- std::pair<BasicBlock *, Value *> AdditionalBypass) {
- assert(((AdditionalBypass.first && AdditionalBypass.second) ||
- (!AdditionalBypass.first && !AdditionalBypass.second)) &&
- "Inconsistent information about additional bypass.");
+void InnerLoopVectorizer::createInductionResumeVPValues(
+ const SCEV2ValueTy &ExpandedSCEVs, Value *AdditionalBypassValue) {
// We are going to resume the execution of the scalar loop.
- // Go over all of the induction variables that we found and fix the
- // PHIs that are left in the scalar version of the loop.
- // The starting values of PHI nodes depend on the counter of the last
- // iteration in the vectorized loop.
- // If we come from a bypass edge then we need to start from the original
- // start value.
- for (const auto &InductionEntry : Legal->getInductionVars()) {
- PHINode *OrigPhi = InductionEntry.first;
- const InductionDescriptor &II = InductionEntry.second;
- PHINode *BCResumeVal = createInductionResumeValue(
- OrigPhi, II, getExpandedStep(II, ExpandedSCEVs), LoopBypassBlocks,
- AdditionalBypass);
- OrigPhi->setIncomingValueForBlock(LoopScalarPreHeader, BCResumeVal);
+ // Go over all of the induction variable PHIs of the scalar loop header and
+ // fix their starting values, which depend on the counter of the last
+ // iteration of the vectorized loop. If we come from one of the
+ // LoopBypassBlocks then we need to start from the original start value. If we
+ // come from the AdditionalBypass then we need to start from its value.
+ VPBasicBlock *ScalarPHVPBB = Plan.getScalarPreheader();
+ VPBuilder ScalarPHBuilder(ScalarPHVPBB, ScalarPHVPBB->begin());
+ for (VPRecipeBase &R : *Plan.getScalarHeader()) {
+ auto *PhiR = cast<VPIRInstruction>(&R);
+ auto *Phi = dyn_cast<PHINode>(&PhiR->getInstruction());
+ if (!Phi)
+ break;
+ if (!Legal->getInductionVars().contains(Phi))
+ continue;
+ const InductionDescriptor &II = Legal->getInductionVars().find(Phi)->second;
+ createInductionResumeVPValue(PhiR, II, getExpandedStep(II, ExpandedSCEVs),
+ LoopBypassBlocks, ScalarPHBuilder,
+ AdditionalBypassValue);
----------------
fhahn wrote:
Updated thanks
https://github.com/llvm/llvm-project/pull/110577
More information about the llvm-commits
mailing list