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

Igor Kirillov via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 2 07:13:24 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())
----------------
igogo-x86 wrote:

@fhahn Well, if I make it as assert, these tests fail:

```
  LLVM :: Transforms/LoopVectorize/AArch64/clamped-trip-count.ll
  LLVM :: Transforms/LoopVectorize/RISCV/low-trip-count.ll
  LLVM :: Transforms/LoopVectorize/RISCV/short-trip-count.ll
  LLVM :: Transforms/LoopVectorize/RISCV/truncate-to-minimal-bitwidth-cost.ll
```

Without assert two RISCV tests show different output (that's why I added this check in the first place)

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


More information about the llvm-commits mailing list