[llvm] [LV]: Teach LV to recursively (de)interleave. (PR #89018)

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 14 08:53:49 PST 2024


================
@@ -2773,10 +2773,22 @@ static Value *interleaveVectors(IRBuilderBase &Builder, ArrayRef<Value *> Vals,
   // Scalable vectors cannot use arbitrary shufflevectors (only splats), so
   // must use intrinsics to interleave.
   if (VecTy->isScalableTy()) {
-    VectorType *WideVecTy = VectorType::getDoubleElementsVectorType(VecTy);
-    return Builder.CreateIntrinsic(WideVecTy, Intrinsic::vector_interleave2,
-                                   Vals,
-                                   /*FMFSource=*/nullptr, Name);
+    unsigned InterleaveFactor = Vals.size();
+    SmallVector<Value *> InterleavingValues(Vals);
+    // As we are interleaving, the values sz will be shrinked until we have the
+    // single final interleaved value.
+    for (unsigned Midpoint = Factor / 2; Midpoint > 0; Midpoint /= 2) {
+      VectorType *InterleaveTy =
+          cast<VectorType>(InterleavingValues[0]->getType());
+      VectorType *WideVecTy =
+          VectorType::getDoubleElementsVectorType(InterleaveTy);
----------------
paulwalker-arm wrote:

Up to you but you could hoist part of this out so you'd end up with:
```
VectorType *InterleaveTy = cast<VectorType>(InterleavingValues[0]->getType());
for (unsigned Midpoint = Factor / 2; Midpoint > 0; Midpoint /= 2) {
  InterleaveTy = VectorType::getDoubleElementsVectorType(InterleaveTy);
  .....
```


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


More information about the llvm-commits mailing list