[llvm] [LoopVectorizer] Prune VFs based on plan register pressure (PR #132190)
Sam Tebbs via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 14 02:21:00 PDT 2025
================
@@ -7792,6 +7582,29 @@ VectorizationFactor LoopVectorizationPlanner::computeBestVF() {
VectorizationFactor LegacyVF = selectVectorizationFactor();
VPlan &BestPlan = getPlanFor(BestFactor.Width);
+ // VPlan calculates register pressure from the plan, so it can come to
+ // different conclusions than the legacy cost model.
+ bool RegUsageDeterminedVF = false;
+ if (BestFactor.Width != LegacyVF.Width) {
+ SmallVector<ElementCount, 1> LegacyVFs = {LegacyVF.Width};
+ SmallVector<ElementCount, 1> VFs = {BestFactor.Width};
+
+ auto LegacyRUs =
+ calculateRegisterUsage(getPlanFor(LegacyVF.Width), LegacyVFs, TTI);
+ auto RUs = calculateRegisterUsage(BestPlan, VFs, TTI);
+
+ auto GetMaxUsage = [](SmallMapVector<unsigned, unsigned, 4> MaxLocalUsers) {
+ unsigned Max = 0;
+ for (auto Pair : MaxLocalUsers)
+ if (Pair.second > Max)
+ Max = Pair.second;
+ return Max;
+ };
+ unsigned MaxLegacyRegUsage = GetMaxUsage(LegacyRUs[0].MaxLocalUsers);
+ unsigned MaxRegUsage = GetMaxUsage(RUs[0].MaxLocalUsers);
+ RegUsageDeterminedVF = MaxRegUsage <= MaxLegacyRegUsage;
----------------
SamTebbs33 wrote:
I've managed to get rid of these changes by checking the register pressure as part of the legacy cost model's VF selection, which mirrors the current behaviour. This has had the knock-on effect of changing some debug output for lots of x86 tests since the plan is used for reg pressure checks, rather than the scalar loop.
https://github.com/llvm/llvm-project/pull/132190
More information about the llvm-commits
mailing list