[PATCH] D97861: [LoopVectorize][NFC] Refactor code to use IRBuilder::CreateStepVector
David Sherwood via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 4 07:12:59 PST 2021
david-arm updated this revision to Diff 328165.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D97861/new/
https://reviews.llvm.org/D97861
Files:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -2240,8 +2240,10 @@
Value *InnerLoopVectorizer::getStepVector(Value *Val, int StartIdx, Value *Step,
Instruction::BinaryOps BinOp) {
// Create and check the types.
- auto *ValVTy = cast<FixedVectorType>(Val->getType());
- int VLen = ValVTy->getNumElements();
+ assert(isa<FixedVectorType>(Val->getType()) &&
+ "Creation of scalable step vector not yet supported");
+ auto *ValVTy = cast<VectorType>(Val->getType());
+ ElementCount VLen = ValVTy->getElementCount();
Type *STy = Val->getType()->getScalarType();
assert((STy->isIntegerTy() || STy->isFloatingPointTy()) &&
@@ -2250,31 +2252,34 @@
SmallVector<Constant *, 8> Indices;
- if (STy->isIntegerTy()) {
- // Create a vector of consecutive numbers from zero to VF.
- for (int i = 0; i < VLen; ++i)
- Indices.push_back(ConstantInt::get(STy, StartIdx + i));
+ // Create a vector of consecutive numbers from zero to VF.
+ VectorType *InitVecValVTy = ValVTy;
+ Type *InitVecValSTy = STy;
+ if (STy->isFloatingPointTy()) {
+ InitVecValSTy =
+ IntegerType::get(STy->getContext(), STy->getScalarSizeInBits());
+ InitVecValVTy = VectorType::get(InitVecValSTy, VLen);
+ }
+ Value *InitVec = Builder.CreateStepVector(InitVecValVTy);
+
+ // Add on StartIdx
+ Value *StartIdxSplat = Builder.CreateVectorSplat(
+ VLen, ConstantInt::get(InitVecValSTy, StartIdx));
+ InitVec = Builder.CreateAdd(InitVec, StartIdxSplat);
- // Add the consecutive indices to the vector value.
- Constant *Cv = ConstantVector::get(Indices);
- assert(Cv->getType() == Val->getType() && "Invalid consecutive vec");
+ if (STy->isIntegerTy()) {
Step = Builder.CreateVectorSplat(VLen, Step);
assert(Step->getType() == Val->getType() && "Invalid step vec");
// FIXME: The newly created binary instructions should contain nsw/nuw flags,
// which can be found from the original scalar operations.
- Step = Builder.CreateMul(Cv, Step);
+ Step = Builder.CreateMul(InitVec, Step);
return Builder.CreateAdd(Val, Step, "induction");
}
// Floating point induction.
assert((BinOp == Instruction::FAdd || BinOp == Instruction::FSub) &&
"Binary Opcode should be specified for FP induction");
- // Create a vector of consecutive numbers from zero to VF.
- for (int i = 0; i < VLen; ++i)
- Indices.push_back(ConstantFP::get(STy, (double)(StartIdx + i)));
-
- // Add the consecutive indices to the vector value.
- Constant *Cv = ConstantVector::get(Indices);
+ InitVec = Builder.CreateUIToFP(InitVec, ValVTy);
Step = Builder.CreateVectorSplat(VLen, Step);
@@ -2282,7 +2287,7 @@
FastMathFlags Flags;
Flags.setFast();
- Value *MulOp = Builder.CreateFMul(Cv, Step);
+ Value *MulOp = Builder.CreateFMul(InitVec, Step);
if (isa<Instruction>(MulOp))
// Have to check, MulOp may be a constant
cast<Instruction>(MulOp)->setFastMathFlags(Flags);
@@ -4612,12 +4617,12 @@
// phi as base and a vectorized version of the step value
// (<step*0, ..., step*N>) as offset.
for (unsigned Part = 0; Part < State.UF; ++Part) {
- SmallVector<Constant *, 8> Indices;
+ Type *VecPhiType = VectorType::get(PhiType, State.VF);
+ Value *StartOffset =
+ ConstantInt::get(VecPhiType, Part * State.VF.getKnownMinValue());
// Create a vector of consecutive numbers from zero to VF.
- for (unsigned i = 0; i < State.VF.getKnownMinValue(); ++i)
- Indices.push_back(
- ConstantInt::get(PhiType, i + Part * State.VF.getKnownMinValue()));
- Constant *StartOffset = ConstantVector::get(Indices);
+ StartOffset =
+ Builder.CreateAdd(StartOffset, Builder.CreateStepVector(VecPhiType));
Value *GEP = Builder.CreateGEP(
ScStValueType->getPointerElementType(), NewPointerPhi,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97861.328165.patch
Type: text/x-patch
Size: 4088 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210304/ce45906b/attachment.bin>
More information about the llvm-commits
mailing list