diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -10467,7 +10467,10 @@ } assert(ResumeV && "Must have a resume value"); VPValue *StartVal = BestEpiPlan.getOrAddExternalDef(ResumeV); - cast(&R)->setStartValue(StartVal); + if (auto *PhiR = dyn_cast(&R)) + PhiR->setStartValue(StartVal); + else if (auto *PhiR = dyn_cast(&R)) + PhiR->setStartValue(StartVal); } LVP.executePlan(EPI.EpilogueVF, EPI.EpilogueUF, BestEpiPlan, EpilogILV, 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 @@ -1061,6 +1061,9 @@ VPValue *getStartValue() { return getOperand(0); } const VPValue *getStartValue() const { return getOperand(0); } + /// Sets the start value of the induction + void setStartValue(VPValue *V) { setOperand(0, V); } + /// Returns the step value of the induction. VPValue *getStepValue() { return getOperand(1); } const VPValue *getStepValue() const { return getOperand(1); }