Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -1113,9 +1113,18 @@ namespace llvm { /// Return the runtime value for VF. -Value *getRuntimeVF(IRBuilder<> &B, Type *Ty, ElementCount VF) { +Value *getRuntimeVF(IRBuilder<> &B, Type *OrigTy, ElementCount VF) { + Type *Ty = OrigTy; + if (Ty->isFloatingPointTy()) + Ty = IntegerType::get(Ty->getContext(), Ty->getScalarSizeInBits()); + Constant *EC = ConstantInt::get(Ty, VF.getKnownMinValue()); - return VF.isScalable() ? B.CreateVScale(EC) : EC; + Value *Res = VF.isScalable() ? B.CreateVScale(EC) : EC; + + if (OrigTy->isFloatingPointTy()) + Res = B.CreateSIToFP(Res, OrigTy); + + return Res; } void reportVectorizationFailure(const StringRef DebugMsg, @@ -2303,13 +2312,7 @@ // Multiply the vectorization factor by the step using integer or // floating-point arithmetic as appropriate. - Type *StepType = Step->getType(); - if (Step->getType()->isFloatingPointTy()) - StepType = IntegerType::get(StepType->getContext(), - StepType->getScalarSizeInBits()); - Value *RuntimeVF = getRuntimeVF(Builder, StepType, VF); - if (Step->getType()->isFloatingPointTy()) - RuntimeVF = Builder.CreateSIToFP(RuntimeVF, Step->getType()); + Value *RuntimeVF = getRuntimeVF(Builder, Step->getType(), VF); Value *Mul = Builder.CreateBinOp(MulOp, Step, RuntimeVF); // Create a vector splat to use in the induction update.