Skip to content

Commit 92d0924

Browse files
authored
[VPlan] Fall back to scalar epilogue if possible when EVL isn't legal (#150908)
When enabling predicated vectorization by default on RISC-V, there's a bunch of performance regressions on llvm-test-suite's LoopInterleaving microbenchmarks: https://lnt.lukelau.me/db_default/v4/nts/788?show_delta=yes&show_previous=yes&show_stddev=yes&show_mad=yes&show_all=yes&show_all_samples=yes&show_sample_counts=yes&show_small_diff=yes&num_comparison_runs=0&test_filter=&test_min_value_filter=&aggregation_fn=min&MW_confidence_lv=0.05&compare_to=791&baseline=730&submit=Update Most of these regressions stem from the interleave_count pragma, which causes EVL tail folding interleaving to be unsupported (since we don't support unrolling with EVL) Currently if DataWithEVL isn't legal we fall back to DataWithoutLaneMask as the tail folding style, but this is very slow on RISC-V. The order of performance roughly is something like: DataWithEVL > None (scalar-epilogue) > Data[WithoutLaneMask] So this patch tries to prevent the regressions by falling back to a scalar epilogue where possible, i.e. the existing vectorization we have today. Not we may still need to fall back to DataWithoutLaneMask, e.g. if the trip count is low etc or it's forced by -prefer-predicate-over-epilogue=predicate-dont-vectorize.
1 parent e19743b commit 92d0924

File tree

3 files changed

+133
-143
lines changed

3 files changed

+133
-143
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,11 +1363,15 @@ class LoopVectorizationCostModel {
13631363
TTI.hasActiveVectorLength() && !EnableVPlanNativePath;
13641364
if (EVLIsLegal)
13651365
return;
1366-
// If for some reason EVL mode is unsupported, fallback to
1367-
// DataWithoutLaneMask to try to vectorize the loop with folded tail
1368-
// in a generic way.
1369-
ChosenTailFoldingStyle = {TailFoldingStyle::DataWithoutLaneMask,
1370-
TailFoldingStyle::DataWithoutLaneMask};
1366+
// If for some reason EVL mode is unsupported, fallback to a scalar epilogue
1367+
// if it's allowed, or DataWithoutLaneMask otherwise.
1368+
if (ScalarEpilogueStatus == CM_ScalarEpilogueAllowed ||
1369+
ScalarEpilogueStatus == CM_ScalarEpilogueNotNeededUsePredicate)
1370+
ChosenTailFoldingStyle = {TailFoldingStyle::None, TailFoldingStyle::None};
1371+
else
1372+
ChosenTailFoldingStyle = {TailFoldingStyle::DataWithoutLaneMask,
1373+
TailFoldingStyle::DataWithoutLaneMask};
1374+
13711375
LLVM_DEBUG(
13721376
dbgs() << "LV: Preference for VP intrinsics indicated. Will "
13731377
"not try to generate VP Intrinsics "

0 commit comments

Comments
 (0)