[llvm] Re-land [Transform][LoadStoreVectorizer] allow redundant in Chain (PR #168135)

Drew Kersnar via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 19 08:48:05 PST 2025


================
@@ -909,27 +936,32 @@ bool Vectorizer::vectorizeChain(Chain &C) {
         llvm::min_element(C, [](const auto &A, const auto &B) {
           return A.Inst->comesBefore(B.Inst);
         })->Inst);
-
+    // This can happen due to a chain of redundant loads.
+    // In this case, just use the element-type, and avoid ExtractElement.
+    if (NumElem == 1)
+      VecTy = VecElemTy;
     // Chain is in offset order, so C[0] is the instr with the lowest offset,
     // i.e. the root of the vector.
     VecInst = Builder.CreateAlignedLoad(VecTy,
                                         getLoadStorePointerOperand(C[0].Inst),
                                         Alignment);
 
-    unsigned VecIdx = 0;
     for (const ChainElem &E : C) {
       Instruction *I = E.Inst;
       Value *V;
       Type *T = getLoadStoreType(I);
+      unsigned EOffset =
+          (E.OffsetFromLeader - C[0].OffsetFromLeader).getSExtValue();
+      unsigned VecIdx = 8 * EOffset / DL.getTypeSizeInBits(VecElemTy);
----------------
dakersnar wrote:

Given our assumption that EOffset will always be non-negative, we should be able to use ZExtValue.
```suggestion
      unsigned EOffset =
          (E.OffsetFromLeader - C[0].OffsetFromLeader).getZExtValue();
      unsigned VecIdx = 8 * EOffset / DL.getTypeSizeInBits(VecElemTy);
```

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


More information about the llvm-commits mailing list