diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -1845,7 +1845,8 @@ /// Check if the induction described by \p ID is canonical, i.e. has the same /// start, step (of 1), and type as the canonical IV. - bool isCanonical(const InductionDescriptor &ID, Type *Ty) const; + bool isCanonical(const InductionDescriptor &ID, VPValue *Step, + Type *Ty) const; }; /// A recipe for generating the active lane mask for the vector loop that is diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -736,7 +736,9 @@ bool VPWidenIntOrFpInductionRecipe::isCanonical() const { auto *StartC = dyn_cast(getStartValue()->getLiveInIRValue()); - auto *StepC = dyn_cast(getInductionDescriptor().getStep()); + if (getStepValue()->getDefiningRecipe()) + return false; + auto *StepC = dyn_cast(getStepValue()->getLiveInIRValue()); return StartC && StartC->isZero() && StepC && StepC->isOne(); } @@ -1092,7 +1094,7 @@ #endif bool VPCanonicalIVPHIRecipe::isCanonical(const InductionDescriptor &ID, - Type *Ty) const { + VPValue *Step, Type *Ty) const { if (Ty != getScalarType()) return false; // The start value of ID must match the start value of this canonical @@ -1100,11 +1102,15 @@ if (getStartValue()->getLiveInIRValue() != ID.getStartValue()) return false; - ConstantInt *Step = ID.getConstIntStepValue(); + // If the step is defined by a recipe, it is not a ConstantInt. + if (Step->getDefiningRecipe()) + return false; + + ConstantInt *StepC = dyn_cast(Step->getLiveInIRValue()); // ID must also be incremented by one. IK_IntInduction always increment the // induction by Step, but the binary op may not be set. - return ID.getKind() == InductionDescriptor::IK_IntInduction && Step && - Step->isOne(); + return ID.getKind() == InductionDescriptor::IK_IntInduction && StepC && + StepC->isOne(); } bool VPWidenPointerInductionRecipe::onlyScalarsGenerated(ElementCount VF) { diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -520,7 +520,7 @@ VPValue *Step = vputils::getOrCreateVPValueForSCEVExpr(Plan, ID.getStep(), SE); VPValue *BaseIV = CanonicalIV; - if (!CanonicalIV->isCanonical(ID, ResultTy)) { + if (!CanonicalIV->isCanonical(ID, Step, ResultTy)) { BaseIV = new VPDerivedIVRecipe(ID, WideIV->getStartValue(), CanonicalIV, Step, ResultTy); HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);