[llvm] [AArch64] Increase the max interleave factor to 4 for loops with reductions (PR #205612)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 25 05:08:17 PDT 2026


================
@@ -8356,7 +8358,7 @@ LoopVectorizeResult LoopVectorizePass::runImpl(Function &F) {
   // vector registers, loop vectorization may still enable scalar
   // interleaving.
   if (!TTI->getNumberOfRegisters(TTI->getRegisterClassForType(true)) &&
-      TTI->getMaxInterleaveFactor(ElementCount::getFixed(1)) < 2)
+      TTI->getMaxInterleaveFactor(ElementCount::getFixed(1), false) < 2)
----------------
david-arm wrote:

I think the code is making the assumption that targets are more likely to increase the interleave factor for reductions, rather than reduce it. That's probably true, but if a target really does return IC=1 for reductions and IC=2 without then we'd still attempt to vectorise based on the more optimistic IC=2.

However, I'm not sure how we can do this properly without significant refactoring and possibly wasted computation. In order to guarantee that we honour the target's max interleave factor in either case I think we'd need to do

```
  if (!TTI->getNumberOfRegisters(TTI->getRegisterClassForType(true)) &&
      (TTI->getMaxInterleaveFactor(ElementCount::getFixed(1), false) < 2 ||
      TTI->getMaxInterleaveFactor(ElementCount::getFixed(1), true) < 2))
```

to cover all cases. What do you think?

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


More information about the llvm-commits mailing list