Skip to content

Commit 0a3352a

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. This is used in #95819.
1 parent 35ddc17 commit 0a3352a

File tree

6 files changed

+23
-0
lines changed

6 files changed

+23
-0
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

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

1677+
/// \returns True if the targets prefers fixed width vectorization if the
1678+
/// loop vectorizer's cost-model assigns an equal cost to the fixed and
1679+
/// scalable version of the vectorized loop.
1680+
bool preferFixedIfEqualToScalable() const;
1681+
16771682
/// \returns True if the target prefers reductions in loop.
16781683
bool preferInLoopReduction(unsigned Opcode, Type *Ty,
16791684
ReductionFlags Flags) const;
@@ -2143,6 +2148,7 @@ class TargetTransformInfo::Concept {
21432148
virtual unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize,
21442149
unsigned ChainSizeInBytes,
21452150
VectorType *VecTy) const = 0;
2151+
virtual bool preferFixedIfEqualToScalable() const = 0;
21462152
virtual bool preferInLoopReduction(unsigned Opcode, Type *Ty,
21472153
ReductionFlags) const = 0;
21482154
virtual bool preferPredicatedReductionSelect(unsigned Opcode, Type *Ty,
@@ -2873,6 +2879,9 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
28732879
VectorType *VecTy) const override {
28742880
return Impl.getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy);
28752881
}
2882+
bool preferFixedIfEqualToScalable() const override {
2883+
return Impl.preferFixedIfEqualToScalable();
2884+
}
28762885
bool preferInLoopReduction(unsigned Opcode, Type *Ty,
28772886
ReductionFlags Flags) const override {
28782887
return Impl.preferInLoopReduction(Opcode, Ty, Flags);

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

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

916+
bool preferFixedIfEqualToScalable() const { return false; }
917+
916918
bool preferInLoopReduction(unsigned Opcode, Type *Ty,
917919
TTI::ReductionFlags Flags) const {
918920
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@ class AArch64TTIImpl : public BasicTTIImplBase<AArch64TTIImpl> {
371371
return TailFoldingStyle::DataWithoutLaneMask;
372372
}
373373

374+
bool preferFixedIfEqualToScalable() const {
375+
return ST->useFixedIfEqualToScalable();
376+
}
377+
374378
bool preferPredicateOverEpilogue(TailFoldingInfo *TFI);
375379

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

0 commit comments

Comments
 (0)