[llvm] [VPlan] Don't use the legacy cost model for loop conditions (PR #156864)
John Brawn via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 9 06:17:39 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)) {
----------------
john-brawn-arm wrote:
> Could we still add the IR instructions to the set to skip?
I've made this change. Doing this we also need to detect when VPInstruction::computeCost will return zero for BranchOnCount, as otherwise the assertion fails in llvm/test/Transforms/LoopVectorize/RISCV/low-trip-count.ll.
https://github.com/llvm/llvm-project/pull/156864
More information about the llvm-commits
mailing list