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 @@ -1103,11 +1103,10 @@ } /// Return a value for Step multiplied by VF. -static Value *createStepForVF(IRBuilder<> &B, Constant *Step, ElementCount VF) { - assert(isa(Step) && "Expected an integer step"); - Constant *StepVal = ConstantInt::get( - Step->getType(), - cast(Step)->getSExtValue() * VF.getKnownMinValue()); +static Value *createStepForVF(IRBuilder<> &B, Type *Ty, ElementCount VF, + int64_t Step) { + assert(Ty->isIntegerTy() && "Expected an integer step"); + Constant *StepVal = ConstantInt::get(Ty, Step * VF.getKnownMinValue()); return VF.isScalable() ? B.CreateVScale(StepVal) : StepVal; } @@ -2620,8 +2619,7 @@ } for (unsigned Part = 0; Part < UF; ++Part) { - Value *StartIdx0 = - createStepForVF(Builder, ConstantInt::get(IntStepTy, Part), VF); + Value *StartIdx0 = createStepForVF(Builder, IntStepTy, VF, Part); if (!IsUniform && VF.isScalable()) { auto *SplatStartIdx = Builder.CreateVectorSplat(VF, StartIdx0); @@ -2963,7 +2961,8 @@ if (isMaskRequired) // Reverse of a null all-one mask is a null mask. BlockInMaskParts[Part] = reverseVector(BlockInMaskParts[Part]); } else { - Value *Increment = createStepForVF(Builder, Builder.getInt32(Part), VF); + Value *Increment = + createStepForVF(Builder, Builder.getInt32Ty(), VF, Part); PartPtr = cast( Builder.CreateGEP(ScalarDataTy, Ptr, Increment)); PartPtr->setIsInBounds(InBounds); @@ -3182,7 +3181,7 @@ Type *Ty = TC->getType(); // This is where we can make the step a runtime constant. - Value *Step = createStepForVF(Builder, ConstantInt::get(Ty, UF), VF); + Value *Step = createStepForVF(Builder, Ty, VF, UF); // If the tail is to be folded by masking, round the number of iterations N // up to a multiple of Step instead of rounding down. This is done by first @@ -3272,8 +3271,7 @@ // If tail is to be folded, vector loop takes care of all iterations. Value *CheckMinIters = Builder.getFalse(); if (!Cost->foldTailByMasking()) { - Value *Step = - createStepForVF(Builder, ConstantInt::get(Count->getType(), UF), VF); + Value *Step = createStepForVF(Builder, Count->getType(), VF, UF); CheckMinIters = Builder.CreateICmp(P, Count, Step, "min.iters.check"); } // Create new preheader for vector loop. @@ -3749,7 +3747,7 @@ // The loop step is equal to the vectorization factor (num of SIMD elements) // times the unroll factor (num of SIMD instructions). Builder.SetInsertPoint(&*Lp->getHeader()->getFirstInsertionPt()); - Value *Step = createStepForVF(Builder, ConstantInt::get(IdxTy, UF), VF); + Value *Step = createStepForVF(Builder, IdxTy, VF, UF); Value *CountRoundDown = getOrCreateVectorTripCount(Lp); Induction = createInductionVariable(Lp, StartIdx, CountRoundDown, Step, @@ -4751,8 +4749,8 @@ } for (unsigned Part = 0; Part < UF; ++Part) { - Value *PartStart = createStepForVF( - Builder, ConstantInt::get(PtrInd->getType(), Part), VF); + Value *PartStart = + createStepForVF(Builder, PtrInd->getType(), VF, Part); if (NeedsVectorIndex) { // Here we cache the whole vector, which means we can support the @@ -8460,7 +8458,7 @@ ICmpInst::ICMP_ULE : ICmpInst::ICMP_ULT; Value *CheckMinIters = Builder.CreateICmp( - P, Count, getRuntimeVF(Builder, Count->getType(), VFactor * UFactor), + P, Count, createStepForVF(Builder, Count->getType(), VFactor, UFactor), "min.iters.check"); if (!ForEpilogue) @@ -8612,10 +8610,11 @@ auto P = Cost->requiresScalarEpilogue(EPI.EpilogueVF) ? ICmpInst::ICMP_ULE : ICmpInst::ICMP_ULT; - Value *CheckMinIters = Builder.CreateICmp( - P, Count, - getRuntimeVF(Builder, Count->getType(), EPI.EpilogueVF * EPI.EpilogueUF), - "min.epilog.iters.check"); + Value *CheckMinIters = + Builder.CreateICmp(P, Count, + createStepForVF(Builder, Count->getType(), + EPI.EpilogueVF, EPI.EpilogueUF), + "min.epilog.iters.check"); ReplaceInstWithInst( Insert->getTerminator(),