[llvm] [LV] Don't trigger legacy/vplan assert when forcing costs (PR #156870)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 11 03:17:17 PDT 2025
================
@@ -7047,7 +7047,13 @@ VectorizationFactor LoopVectorizationPlanner::computeBestVF() {
// Verify that the VPlan-based and legacy cost models agree, except for VPlans
// with early exits and plans with additional VPlan simplifications. The
// legacy cost model doesn't properly model costs for such loops.
+ // NOTE: If the user has forced a target instruction cost this assert is very
+ // likely to trigger because the VPlan recipes don't map 1:1 with the scalar
+ // instructions that the legacy cost model is based on. One example of this is
+ // for interleave groups - VPlan will use the forced cost for the whole group,
+ // whereas the legacy cost model will use it for each load.
assert((BestFactor.Width == LegacyVF.Width || BestPlan.hasEarlyExit() ||
+ ForceTargetInstructionCost.getNumOccurrences() > 0 ||
----------------
fhahn wrote:
Hmm, it depends I guess, both cost models still try to compute the costs of the same result.
The difference is to either consider the cost of all instructions together in an interleave group as the the forced cost (what VPInterleaveRecipe does currently) or ignore the fact that members of the group will be combined and used the forced cost for each member.
I think one could argue for either behavior (VPInterleaveRecipe will generate a single memory op, but it is very wide and in practice we should end up with one legal memory op per member); it just would be preferable to have a consistent meaning for the flag.
I've not looked into it yet, but I *think* we could also match the behavior of VPInterleaveRecipe in the legacy cost model, by checking if the instruction should get lowered to an interleave group, and if so only apply the forced cost to the insertion point member.
https://github.com/llvm/llvm-project/pull/156870
More information about the llvm-commits
mailing list