Skip to content

Commit 76d98cf

Browse files
Mel-Chenpreames
andauthored
[RISCV][TTI] Enable masked interleave access (#151665)
Now that support for masked loads/stores of interleave groups has landed, we can enable the loop vectorizer to generate masked interleave access where applicable. This improves vectorization in several ways: * Internal predication support: This enables interleave group vectorization for loops with internal control flow predication, provided all members of the group share the same predicate. Gaps in interleave groups are still not efficiently handled by masking, so masking for gaps remains disabled for now. * Tail folding: This allows tail folding of loops with interleave groups by using masking. Without this, vectorized loops with interleaves would fall back to using separate gather/scatter accesses, which can be significantly less efficient. "[RISCV][TTI] Enable masked interleave access for scalable vector (#149981)" was reverted by 5294793 due to triggering an assertion. The issue has been addressed in the patch "[LV] Fix gap mask requirement for interleaved access (#151105)". On the other hand, this patch also enable fixed-length masked interleave access (#150624) since support for fixed-length has also been landed 992118c. --------- Co-authored-by: Philip Reames <[email protected]>
1 parent 155359c commit 76d98cf

File tree

4 files changed

+155
-186
lines changed

4 files changed

+155
-186
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -979,11 +979,11 @@ InstructionCost RISCVTTIImpl::getInterleavedMemoryOpCost(
979979
Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
980980
bool UseMaskForCond, bool UseMaskForGaps) const {
981981

982-
// The interleaved memory access pass will lower interleaved memory ops (i.e
983-
// a load and store followed by a specific shuffle) to vlseg/vsseg
984-
// intrinsics.
985-
if (!UseMaskForCond && !UseMaskForGaps &&
986-
Factor <= TLI->getMaxSupportedInterleaveFactor()) {
982+
// The interleaved memory access pass will lower (de)interleave ops combined
983+
// with an adjacent appropriate memory to vlseg/vsseg intrinsics. vlseg/vsseg
984+
// only support masking per-iteration (i.e. condition), not per-segment (i.e.
985+
// gap).
986+
if (!UseMaskForGaps && Factor <= TLI->getMaxSupportedInterleaveFactor()) {
987987
auto *VTy = cast<VectorType>(VecTy);
988988
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(VTy);
989989
// Need to make sure type has't been scalarized

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@ class RISCVTTIImpl final : public BasicTTIImplBase<RISCVTTIImpl> {
398398

399399
bool enableInterleavedAccessVectorization() const override { return true; }
400400

401+
bool enableMaskedInterleavedAccessVectorization() const override {
402+
return ST->hasVInstructions();
403+
}
404+
401405
unsigned getMinTripCountTailFoldingThreshold() const override;
402406

403407
enum RISCVRegisterClass { GPRRC, FPRRC, VRRC };

0 commit comments

Comments
 (0)