Skip to content

Commit 0a0aa2e

Browse files
committed
Simplify pre-gap-filling TTI legality check
1 parent 030c0bb commit 0a0aa2e

File tree

1 file changed

+20
-46
lines changed

1 file changed

+20
-46
lines changed

llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,6 @@ class Vectorizer {
354354
bool accessIsAllowedAndFast(unsigned SizeBytes, unsigned AS, Align Alignment,
355355
unsigned VecElemBits) const;
356356

357-
/// Before attempting to fill gaps, check if the chain is a candidate for
358-
/// a masked load/store, to save compile time if it is not possible for the
359-
/// address space and element type.
360-
bool shouldAttemptMaskedLoadStore(const ArrayRef<ChainElem> C) const;
361-
362357
/// Create a new GEP and a new Load/Store instruction such that the GEP
363358
/// is pointing at PrevElem + Offset. In the case of stores, store poison.
364359
/// Extra elements will either be combined into a masked load/store or
@@ -665,14 +660,27 @@ std::vector<Chain> Vectorizer::splitChainByContiguity(Chain &C) {
665660

666661
// If the chain is not contiguous, we try to fill the gap with "extra"
667662
// elements to artificially make it contiguous, to try to enable
668-
// vectorization. We only fill gaps if there is a potentially legal masked
669-
// load/store for the target. If later on, we don't end up with a chain that
670-
// could be vectorized into a legal masked load/store, the chains with extra
671-
// elements will be filtered out in splitChainByAlignment.
672-
bool TryFillGaps = shouldAttemptMaskedLoadStore(C);
663+
// vectorization. We only fill gaps if there is potential to end up with a
664+
// legal masked load/store given the target, address space, and element type.
665+
// At this point, when querying the TTI, optimistically assume max alignment
666+
// and max vector size, as splitChainByAlignment will ensure the final vector
667+
// shape passes the legalization check.
668+
unsigned AS = getLoadStoreAddressSpace(C[0].Inst);
669+
Type *ElementType = getLoadStoreType(C[0].Inst)->getScalarType();
670+
unsigned MaxVecRegBits = TTI.getLoadStoreVecRegBitWidth(AS);
671+
Align OptimisticAlign = Align(MaxVecRegBits / 8);
672+
unsigned int MaxVectorNumElems =
673+
MaxVecRegBits / DL.getTypeSizeInBits(ElementType);
674+
FixedVectorType *OptimisticVectorType =
675+
FixedVectorType::get(ElementType, MaxVectorNumElems);
676+
bool TryFillGaps =
677+
isa<LoadInst>(C[0].Inst)
678+
? TTI.isLegalMaskedLoad(OptimisticVectorType, OptimisticAlign, AS,
679+
TTI::MaskKind::ConstantMask)
680+
: TTI.isLegalMaskedStore(OptimisticVectorType, OptimisticAlign, AS,
681+
TTI::MaskKind::ConstantMask);
673682

674-
unsigned ASPtrBits =
675-
DL.getIndexSizeInBits(getLoadStoreAddressSpace(C[0].Inst));
683+
unsigned ASPtrBits = DL.getIndexSizeInBits(AS);
676684

677685
// Compute the alignment of the leader of the chain (which every stored offset
678686
// is based on) using the current first element of the chain. This is
@@ -1861,40 +1869,6 @@ bool Vectorizer::accessIsAllowedAndFast(unsigned SizeBytes, unsigned AS,
18611869
return true;
18621870
}
18631871

1864-
bool Vectorizer::shouldAttemptMaskedLoadStore(
1865-
const ArrayRef<ChainElem> C) const {
1866-
bool IsLoadChain = isa<LoadInst>(C[0].Inst);
1867-
1868-
unsigned AS = getLoadStoreAddressSpace(C[0].Inst);
1869-
Type *ElementType = getLoadStoreType(C[0].Inst)->getScalarType();
1870-
unsigned VecRegBits = TTI.getLoadStoreVecRegBitWidth(AS);
1871-
// Assume max alignment, splitChainByAlignment will legalize it later if the
1872-
// necessary alignment is not reached.
1873-
Align OptimisticAlign = Align(VecRegBits / 8);
1874-
unsigned int MaxVectorNumElems =
1875-
VecRegBits / DL.getTypeSizeInBits(ElementType);
1876-
1877-
// Attempt to find the smallest power-of-two number of elements that, if
1878-
// well aligned, could be represented as a legal masked load/store.
1879-
// If one exists for a given element type and address space, it is worth
1880-
// attempting to fill gaps as we may be able to create a legal masked
1881-
// load/store. If we do not end up with a legal masked load/store, chains with
1882-
// extra elements will be discarded.
1883-
const unsigned MinMaskedStoreNumElems = 4;
1884-
for (unsigned NumElems = MinMaskedStoreNumElems;
1885-
NumElems <= MaxVectorNumElems; NumElems *= 2) {
1886-
FixedVectorType *VectorType = FixedVectorType::get(ElementType, NumElems);
1887-
bool IsLegalMaskedInstruction =
1888-
IsLoadChain ? TTI.isLegalMaskedLoad(VectorType, OptimisticAlign, AS,
1889-
TTI::MaskKind::ConstantMask)
1890-
: TTI.isLegalMaskedStore(VectorType, OptimisticAlign, AS,
1891-
TTI::MaskKind::ConstantMask);
1892-
if (IsLegalMaskedInstruction)
1893-
return true;
1894-
}
1895-
return false;
1896-
}
1897-
18981872
ChainElem Vectorizer::createExtraElementAfter(const ChainElem &Prev,
18991873
APInt Offset, StringRef Prefix,
19001874
Align Alignment) {

0 commit comments

Comments
 (0)