[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
Mon Dec 8 01:32:22 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:

Hmm so I think what is going on is that the original compare will almost always be removed (except if there is another user).

Previously the code would mark all exit instructions to be skipped for cost-computtion (and in turn skipped in planContainsAdditionalSimplifications). But now we don't, so the difference between IR compare and BranchOnCount will cause planContainsAdditionalSimplifications to return true.

Could we still add the IR instructions to the set to skip?

https://github.com/llvm/llvm-project/pull/156864


More information about the llvm-commits mailing list