Skip to content

Commit 9e3fbe4

Browse files
committed
[TTI][AArch64] Add preferFixedIfEqualToScalable hook
This adds a new hook to prefer fixed width loop vectorization over scalable. This will be used in the loop vectoriser to generate more NEON code instead of SVE if cost-model assigns equal costs to fixed and scalable versions of the vectorised loop.
1 parent 35ddc17 commit 9e3fbe4

File tree

6 files changed

+20
-0
lines changed

6 files changed

+20
-0
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,8 @@ class TargetTransformInfo {
16741674
false; ///< If op is an fp min/max, whether NaNs may be present.
16751675
};
16761676

1677+
bool preferFixedIfEqualToScalable() const;
1678+
16771679
/// \returns True if the target prefers reductions in loop.
16781680
bool preferInLoopReduction(unsigned Opcode, Type *Ty,
16791681
ReductionFlags Flags) const;
@@ -2143,6 +2145,7 @@ class TargetTransformInfo::Concept {
21432145
virtual unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize,
21442146
unsigned ChainSizeInBytes,
21452147
VectorType *VecTy) const = 0;
2148+
virtual bool preferFixedIfEqualToScalable() const = 0;
21462149
virtual bool preferInLoopReduction(unsigned Opcode, Type *Ty,
21472150
ReductionFlags) const = 0;
21482151
virtual bool preferPredicatedReductionSelect(unsigned Opcode, Type *Ty,
@@ -2873,6 +2876,9 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
28732876
VectorType *VecTy) const override {
28742877
return Impl.getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy);
28752878
}
2879+
bool preferFixedIfEqualToScalable() const override {
2880+
return Impl.preferFixedIfEqualToScalable();
2881+
}
28762882
bool preferInLoopReduction(unsigned Opcode, Type *Ty,
28772883
ReductionFlags Flags) const override {
28782884
return Impl.preferInLoopReduction(Opcode, Ty, Flags);

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,10 @@ class TargetTransformInfoImplBase {
913913
return VF;
914914
}
915915

916+
bool preferFixedIfEqualToScalable() const {
917+
return false;
918+
}
919+
916920
bool preferInLoopReduction(unsigned Opcode, Type *Ty,
917921
TTI::ReductionFlags Flags) const {
918922
return false;

llvm/lib/Analysis/TargetTransformInfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,10 @@ unsigned TargetTransformInfo::getStoreVectorFactor(unsigned VF,
12821282
return TTIImpl->getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy);
12831283
}
12841284

1285+
bool TargetTransformInfo::preferFixedIfEqualToScalable() const {
1286+
return TTIImpl->preferFixedIfEqualToScalable();
1287+
}
1288+
12851289
bool TargetTransformInfo::preferInLoopReduction(unsigned Opcode, Type *Ty,
12861290
ReductionFlags Flags) const {
12871291
return TTIImpl->preferInLoopReduction(Opcode, Ty, Flags);

llvm/lib/Target/AArch64/AArch64Features.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ def FeatureExperimentalZeroingPseudos
244244
def FeatureUseScalarIncVL : SubtargetFeature<"use-scalar-inc-vl",
245245
"UseScalarIncVL", "true", "Prefer inc/dec over add+cnt">;
246246

247+
def FeatureUseFixedIfEqualToScalable : SubtargetFeature<"use-fixed-if-equal-to-scalable",
248+
"UseFixedIfEqualToScalable", "true", "Prefer fixed width loop vectorization over scalable if cost-model assigns equal costs">;
249+
247250
def FeatureBF16 : Extension<"bf16", "BF16",
248251
"Enable BFloat16 Extension (FEAT_BF16)", [],
249252
"FEAT_BF16", "+bf16", 280>;

llvm/lib/Target/AArch64/AArch64Processors.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ def TuneNeoverseV2 : SubtargetFeature<"neoversev2", "ARMProcFamily", "NeoverseV2
489489
FeatureALULSLFast,
490490
FeaturePostRAScheduler,
491491
FeatureEnableSelectOptimize,
492+
FeatureUseFixedIfEqualToScalable,
492493
FeaturePredictableSelectIsExpensive]>;
493494

494495
def TuneNeoverseV3 : SubtargetFeature<"neoversev3", "ARMProcFamily", "NeoverseV3",

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ class AArch64TTIImpl : public BasicTTIImplBase<AArch64TTIImpl> {
371371
return TailFoldingStyle::DataWithoutLaneMask;
372372
}
373373

374+
bool preferFixedIfEqualToScalable() const { return ST->useFixedIfEqualToScalable(); }
375+
374376
bool preferPredicateOverEpilogue(TailFoldingInfo *TFI);
375377

376378
bool supportsScalableVectors() const { return ST->hasSVE(); }

0 commit comments

Comments
 (0)