[llvm] [VPlan] Don't use the legacy cost model for loop conditions (PR #156864)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 20 02:47:01 PST 2025
================
@@ -6988,6 +6948,35 @@ static bool planContainsAdditionalSimplifications(VPlan &Plan,
});
});
}
+
+static bool planContainsDifferentCompares(VPlan &Plan, VPCostContext &CostCtx,
+ Loop *TheLoop, ElementCount VF) {
+ // Count how many compare instructions there are in the legacy cost model.
+ unsigned NumLegacyCompares = 0;
+ for (BasicBlock *BB : TheLoop->blocks()) {
+ for (auto &I : *BB) {
+ if (isa<CmpInst>(I)) {
+ NumLegacyCompares += 1;
+ }
+ }
+ }
+
+ // Count how many compare instructions there are in the VPlan.
+ unsigned NumVPlanCompares = 0;
+ auto Iter = vp_depth_first_deep(Plan.getVectorLoopRegion()->getEntry());
+ for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(Iter)) {
----------------
fhahn wrote:
Thanks for checking!
It looks like there's still something related to the changes that effectively disables the assertion altogether. I tried the patch with something like the diff below which should cause lots of crashes, but it seems there aren't?
```
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 7c9302860a3b..4d821ca0954c 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -2270,6 +2270,7 @@ InstructionCost VPWidenRecipe::computeCost(ElementCount VF,
case Instruction::ExtractValue:
case Instruction::ICmp:
case Instruction::FCmp:
+ return 100;
return getCostForRecipeWithOpcode(getOpcode(), VF, Ctx);
default:
llvm_unreachable("Unsupported opcode for instruction");
```
https://github.com/llvm/llvm-project/pull/156864
More information about the llvm-commits
mailing list