[llvm] [VPlan] Create header phis once, after constructing VPlan0 (NFC). (PR #168291)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 14 09:29:34 PST 2025
================
@@ -576,6 +576,108 @@ VPlanTransforms::buildVPlan0(Loop *TheLoop, LoopInfo &LI, Type *InductionTy,
return VPlan0;
}
+/// Creates a VPWidenIntOrFpInductionRecipe or VPWidenPointerInductionRecipe
+/// for \p Phi based on \p IndDesc.
+static VPHeaderPHIRecipe *
+createWidenInductionRecipe(PHINode *Phi, VPPhi *PhiR, VPValue *Start,
+ const InductionDescriptor &IndDesc, VPlan &Plan,
+ ScalarEvolution &SE, Loop &OrigLoop, DebugLoc DL) {
+ assert(SE.isLoopInvariant(IndDesc.getStep(), &OrigLoop) &&
+ "step must be loop invariant");
+ assert((Plan.getLiveIn(IndDesc.getStartValue()) == Start ||
+ (SE.isSCEVable(IndDesc.getStartValue()->getType()) &&
+ SE.getSCEV(IndDesc.getStartValue()) ==
+ vputils::getSCEVExprForVPValue(Start, SE))) &&
+ "Start VPValue must match IndDesc's start value");
+
+ VPValue *Step =
+ vputils::getOrCreateVPValueForSCEVExpr(Plan, IndDesc.getStep());
+
+ if (IndDesc.getKind() == InductionDescriptor::IK_PtrInduction)
+ return new VPWidenPointerInductionRecipe(Phi, Start, Step, &Plan.getVFxUF(),
+ IndDesc, DL);
+
+ // Update wide induction increments to use the same step as the corresponding
+ // wide induction. This enables detecting induction increments directly in
+ // VPlan and removes redundant splats.
+ using namespace llvm::VPlanPatternMatch;
+ if (match(PhiR->getOperand(1), m_Add(m_Specific(PhiR), m_VPValue())))
+ PhiR->getOperand(1)->getDefiningRecipe()->setOperand(1, Step);
+
+ // It is always safe to copy over the NoWrap and FastMath flags. In
+ // particular, when folding tail by masking, the masked-off lanes are never
+ // used, so it is safe.
----------------
fhahn wrote:
Currently I don't think it would mislead any user, but there may be poison lanes in the IV with wrap flags, when folding the tail, but masking should make sure that none of those lanes will be used. I think in general various code would already need to account for masked off lanes being poison in general.
https://github.com/llvm/llvm-project/pull/168291
More information about the llvm-commits
mailing list