@@ -1628,6 +1628,10 @@ class LoopVectorizationCostModel {
1628
1628
ElementCount MaxSafeVF,
1629
1629
bool FoldTailByMasking);
1630
1630
1631
+ // / Checks if scalable vectorization is supported and enabled. Caches the
1632
+ // / result to avoid repeated debug dumps for repeated queries.
1633
+ bool isScalableVectorizationAllowed ();
1634
+
1631
1635
// / \return the maximum legal scalable VF, based on the safe max number
1632
1636
// / of elements.
1633
1637
ElementCount getMaxLegalScalableVF (unsigned MaxSafeElements);
@@ -1692,6 +1696,9 @@ class LoopVectorizationCostModel {
1692
1696
std::optional<std::pair<TailFoldingStyle, TailFoldingStyle>>
1693
1697
ChosenTailFoldingStyle;
1694
1698
1699
+ // / true if scalable vectorization is supported and enabled.
1700
+ std::optional<bool > IsScalableVectorizationAllowed;
1701
+
1695
1702
// / A map holding scalar costs for different vectorization factors. The
1696
1703
// / presence of a cost for an instruction in the mapping indicates that the
1697
1704
// / instruction will be scalarized when vectorizing with the associated
@@ -4144,15 +4151,18 @@ bool LoopVectorizationCostModel::runtimeChecksRequired() {
4144
4151
return false ;
4145
4152
}
4146
4153
4147
- ElementCount
4148
- LoopVectorizationCostModel::getMaxLegalScalableVF (unsigned MaxSafeElements) {
4154
+ bool LoopVectorizationCostModel::isScalableVectorizationAllowed () {
4155
+ if (IsScalableVectorizationAllowed)
4156
+ return *IsScalableVectorizationAllowed;
4157
+
4158
+ IsScalableVectorizationAllowed = false ;
4149
4159
if (!TTI.supportsScalableVectors () && !ForceTargetSupportsScalableVectors)
4150
- return ElementCount::getScalable ( 0 ) ;
4160
+ return false ;
4151
4161
4152
4162
if (Hints->isScalableVectorizationDisabled ()) {
4153
4163
reportVectorizationInfo (" Scalable vectorization is explicitly disabled" ,
4154
4164
" ScalableVectorizationDisabled" , ORE, TheLoop);
4155
- return ElementCount::getScalable ( 0 ) ;
4165
+ return false ;
4156
4166
}
4157
4167
4158
4168
LLVM_DEBUG (dbgs () << " LV: Scalable vectorization is available\n " );
@@ -4172,7 +4182,7 @@ LoopVectorizationCostModel::getMaxLegalScalableVF(unsigned MaxSafeElements) {
4172
4182
" Scalable vectorization not supported for the reduction "
4173
4183
" operations found in this loop." ,
4174
4184
" ScalableVFUnfeasible" , ORE, TheLoop);
4175
- return ElementCount::getScalable ( 0 ) ;
4185
+ return false ;
4176
4186
}
4177
4187
4178
4188
// Disable scalable vectorization if the loop contains any instructions
@@ -4184,17 +4194,36 @@ LoopVectorizationCostModel::getMaxLegalScalableVF(unsigned MaxSafeElements) {
4184
4194
reportVectorizationInfo (" Scalable vectorization is not supported "
4185
4195
" for all element types found in this loop." ,
4186
4196
" ScalableVFUnfeasible" , ORE, TheLoop);
4187
- return ElementCount::getScalable (0 );
4197
+ return false ;
4198
+ }
4199
+
4200
+ if (!Legal->isSafeForAnyVectorWidth ()) {
4201
+ std::optional<unsigned > MaxVScale = getMaxVScale (*TheFunction, TTI);
4202
+ if (!MaxVScale) {
4203
+ reportVectorizationInfo (
4204
+ " The target does not provide maximum vscale value." ,
4205
+ " ScalableVFUnfeasible" , ORE, TheLoop);
4206
+ return false ;
4207
+ }
4188
4208
}
4189
4209
4210
+ IsScalableVectorizationAllowed = true ;
4211
+ return true ;
4212
+ }
4213
+
4214
+ ElementCount
4215
+ LoopVectorizationCostModel::getMaxLegalScalableVF (unsigned MaxSafeElements) {
4216
+ if (!isScalableVectorizationAllowed ())
4217
+ return ElementCount::getScalable (0 );
4218
+
4219
+ auto MaxScalableVF = ElementCount::getScalable (
4220
+ std::numeric_limits<ElementCount::ScalarTy>::max ());
4190
4221
if (Legal->isSafeForAnyVectorWidth ())
4191
4222
return MaxScalableVF;
4192
4223
4224
+ std::optional<unsigned > MaxVScale = getMaxVScale (*TheFunction, TTI);
4193
4225
// Limit MaxScalableVF by the maximum safe dependence distance.
4194
- if (std::optional<unsigned > MaxVScale = getMaxVScale (*TheFunction, TTI))
4195
- MaxScalableVF = ElementCount::getScalable (MaxSafeElements / *MaxVScale);
4196
- else
4197
- MaxScalableVF = ElementCount::getScalable (0 );
4226
+ MaxScalableVF = ElementCount::getScalable (MaxSafeElements / *MaxVScale);
4198
4227
4199
4228
if (!MaxScalableVF)
4200
4229
reportVectorizationInfo (
0 commit comments