Skip to content

Commit ee3a771

Browse files
Mel-Chenpreames
andauthored
[RISCV][TTI] Enable masked interleave access for scalable vector (#149981)
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. * Scalable vector support: Currently, only scalable vector types are supported for masked interleave lowering. Fixed-length vector support will be enabled in the future. As interleave access is not yet supported with tail folding by EVL, that functionality is temporarily disabled. We are going to create another patch to support it. Co-authored-by: Philip Reames <[email protected]> --------- Co-authored-by: Philip Reames <[email protected]>
1 parent 1640d51 commit ee3a771

File tree

5 files changed

+152
-193
lines changed

5 files changed

+152
-193
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -979,10 +979,12 @@ 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 &&
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+
// TODO: Support masked interleaved access for fixed length vector.
987+
if ((isa<ScalableVectorType>(VecTy) || !UseMaskForCond) && !UseMaskForGaps &&
986988
Factor <= TLI->getMaxSupportedInterleaveFactor()) {
987989
auto *VTy = cast<VectorType>(VecTy);
988990
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(VTy);

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 };

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,9 @@ class LoopVectorizationCostModel {
13591359
return;
13601360
// Override EVL styles if needed.
13611361
// FIXME: Investigate opportunity for fixed vector factor.
1362+
// FIXME: Support interleave accesses.
13621363
bool EVLIsLegal = UserIC <= 1 && IsScalableVF &&
1364+
!InterleaveInfo.hasGroups() &&
13631365
TTI.hasActiveVectorLength() && !EnableVPlanNativePath;
13641366
if (EVLIsLegal)
13651367
return;

0 commit comments

Comments
 (0)