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

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 28 06:50:39 PST 2024


================
@@ -5557,14 +5576,23 @@ InstructionCost LoopVectorizationCostModel::computePredInstDiscount(
 InstructionCost LoopVectorizationCostModel::expectedCost(ElementCount VF) {
   InstructionCost Cost;
 
+  // If the vector loop gets executed exactly once with the given VF, ignore the
+  // costs of comparison and induction instructions, as they'll get simplified
+  // away.
+  SmallPtrSet<Instruction *, 2> ValuesToIgnoreForVF;
+  auto TC = PSE.getSE()->getSmallConstantTripCount(TheLoop);
+  if (VF.isFixed() && TC == VF.getFixedValue() && !foldTailByMasking())
----------------
fhahn wrote:

If TC == VF, no tail should remain, so we shouldn't try to fold the tail by masking. Could you make this an assert instead?

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


More information about the llvm-commits mailing list