[llvm] [SLP][REVEC] Expand getelementptr into vector form. (PR #103704)

Han-Kuan Chen via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 19 09:35:47 PDT 2024


================
@@ -13760,6 +13760,26 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
           LLVM_DEBUG(dbgs() << "SLP: Diamond merged for " << *VL0 << ".\n");
           return E->VectorizedValue;
         }
+        if (isa<FixedVectorType>(ScalarTy)) {
+          assert(SLPReVec && "FixedVectorType is not expected.");
+          // CreateMaskedGather expects VecTy and VecPtr have same size. We need
+          // to expand VecPtr if ScalarTy is a vector type.
+          unsigned ScalarTyNumElements =
+              cast<FixedVectorType>(ScalarTy)->getNumElements();
+          unsigned VecTyNumElements =
+              cast<FixedVectorType>(VecTy)->getNumElements();
+          SmallVector<Constant *> Indices(VecTyNumElements);
+          transform(seq(VecTyNumElements), Indices.begin(), [=](unsigned I) {
+            return Builder.getInt64(I % ScalarTyNumElements);
+          });
----------------
HanKuanChen wrote:

This case is trying to vectorize the following instructions
```
  %getelementptr0 = getelementptr i8, ptr null, i64 64036
  %getelementptr1 = getelementptr i8, ptr null, i64 64064
  %0 = load <2 x i32>, ptr %getelementptr0, align 4
  %1 = load <2 x i32>, ptr %getelementptr1, align 8
```
So the actual load address is `[64036, 64036 + i32, 64064, 64064 + i32]`.

The `VecPtr` is `<4 x ptr> getelementptr (i32, <4 x ptr> <ptr inttoptr (i64 64036 to ptr), ptr inttoptr (i64 64036 to ptr), ptr inttoptr (i64 64064 to ptr), ptr inttoptr (i64 64064 to ptr)>, <4 x i64> <i64 0, i64 1, i64 0, i64 1>)`.
>From the definition, I though the meaning for `0, 1, 0, 1` is

```
[0] = 64036 + 0 * sizeof(i32)
[1] = 64036 + 1 * sizeof(i32)
[2] = 64064 + 0 * sizeof(i32)
[3] = 64064 + 1 * sizeof(i32)
```

reference: https://llvm.org/docs/LangRef.html#vector-of-pointers


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


More information about the llvm-commits mailing list