Skip to content

Commit

Permalink
[SLP][NFC]Add safe createExtractVector and use instead Builder.Create…
Browse files Browse the repository at this point in the history
…ExtractVector
  • Loading branch information
alexey-bataev committed Jan 17, 2025
1 parent eddeb36 commit fec503d
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4995,6 +4995,23 @@ static Value *createInsertVector(
return Vec;
}

/// Correctly creates extract_subvector, checking that the index is multiple of
/// the subvectors length. Otherwise, generates shuffle using \p Generator or
/// using default shuffle.
static Value *createExtractVector(IRBuilderBase &Builder, Value *Vec,
unsigned SubVecVF, unsigned Index) {
if (Index % SubVecVF == 0) {
VectorType *SubVecTy =
getWidenedType(Vec->getType()->getScalarType(), SubVecVF);
return Builder.CreateExtractVector(SubVecTy, Vec, Builder.getInt64(Index));
}
// Create shuffle, extract_subvector requires that index is multiple of
// the subvector length.
SmallVector<int> Mask(SubVecVF, PoisonMaskElem);
std::iota(Mask.begin(), Mask.end(), Index);
return Builder.CreateShuffleVector(Vec, Mask);
}

BoUpSLP::LoadsState
BoUpSLP::canVectorizeLoads(ArrayRef<Value *> VL, const Value *VL0,
SmallVectorImpl<unsigned> &Order,
Expand Down Expand Up @@ -16550,10 +16567,8 @@ BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues,
// When REVEC is enabled, we need to extract a vector.
// Note: The element size of Scalar may be different from the
// element size of Vec.
Ex = Builder.CreateExtractVector(
FixedVectorType::get(Vec->getType()->getScalarType(),
VecTyNumElements),
Vec, Builder.getInt64(ExternalUse.Lane * VecTyNumElements));
Ex = createExtractVector(Builder, Vec, VecTyNumElements,
ExternalUse.Lane * VecTyNumElements);
} else {
Ex = Builder.CreateExtractElement(Vec, Lane);
}
Expand Down

0 comments on commit fec503d

Please sign in to comment.