Index: llvm/lib/IR/IRBuilder.cpp =================================================================== --- llvm/lib/IR/IRBuilder.cpp +++ llvm/lib/IR/IRBuilder.cpp @@ -81,8 +81,10 @@ } Value *IRBuilderBase::CreateVScale(Constant *Scaling, const Twine &Name) { - Module *M = GetInsertBlock()->getParent()->getParent(); assert(isa(Scaling) && "Expected constant integer"); + if (cast(Scaling)->isZero()) + return Scaling; + Module *M = GetInsertBlock()->getParent()->getParent(); Function *TheFn = Intrinsic::getDeclaration(M, Intrinsic::vscale, {Scaling->getType()}); CallInst *CI = createCallHelper(TheFn, {}, this, Name); Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -4768,10 +4768,9 @@ "Currently unsupported for scalable vectors"); unsigned Lanes = IsUniform ? 1 : State.VF.getFixedValue(); - Value *RuntimeVF = getRuntimeVF(Builder, PtrInd->getType(), VF); for (unsigned Part = 0; Part < UF; ++Part) { - Value *PartStart = Builder.CreateMul( - RuntimeVF, ConstantInt::get(PtrInd->getType(), Part)); + Value *PartStart = createStepForVF( + Builder, ConstantInt::get(PtrInd->getType(), Part), VF); for (unsigned Lane = 0; Lane < Lanes; ++Lane) { Value *Idx = Builder.CreateAdd( PartStart, ConstantInt::get(PtrInd->getType(), Lane));