[llvm] [LV] Ignore some costs when loop gets fully unrolled (PR #106699)

Igor Kirillov via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 13 06:45:38 PST 2024


================
@@ -5544,14 +5544,28 @@ InstructionCost LoopVectorizationCostModel::computePredInstDiscount(
 InstructionCost LoopVectorizationCostModel::expectedCost(ElementCount VF) {
   InstructionCost Cost;
 
+  // If with the given VF loop gets fully unrolled, ignore the costs of
+  // comparison and induction instructions, as they'll get simplified away
+  SmallPtrSet<const Value *, 16> ValuesToIgnoreForVF;
+  auto TC = PSE.getSE()->getSmallConstantTripCount(TheLoop);
+  auto *Cmp = TheLoop->getLatchCmpInst();
+  if (Cmp && TC == VF.getKnownMinValue()) {
----------------
igogo-x86 wrote:

It turns out scalable VF isn't that simple. Branch, next-iteration-induction, and comparison are simplified but only with tail-folding. So, I assume we have to keep only fixed-width FV, as I don't see how I can check the type of prediction here. Branch cost is zero, so I don't do anything about it.

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


More information about the llvm-commits mailing list