[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
Wed Nov 26 02:51:28 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:
The issue with bailing out on some wide accesses should be fixed as of #169249.
> I've changed this to ignore blocks outside of the vector loop region.
It looks like those changes may have been dropped by accident, at least it looks like the current code would still leave the parent region via the deep traversal iterator?
One example that should crash with the PR updated the current `main` and the change below is `llvm/test/Transforms/LoopVectorize/X86/float-induction-x86.ll`, but it does not, presumably because we count the compare in the middle.block?
```
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index c04f510dd995..048a298ef3ce 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -3582,6 +3582,7 @@ void VPPredInstPHIRecipe::printRecipe(raw_ostream &O, const Twine &Indent,
InstructionCost VPWidenMemoryRecipe::computeCost(ElementCount VF,
VPCostContext &Ctx) const {
+ return 100;
Type *Ty = toVectorTy(getLoadStoreType(&Ingredient), VF);
unsigned AS = cast<PointerType>(Ctx.Types.inferScalarType(getAddr()))
->getAddressSpace();
```
https://github.com/llvm/llvm-project/pull/156864
More information about the llvm-commits
mailing list