[Mlir-commits] [mlir] [mlir][vector] Add unroll patterns for vector.load and vector.store (PR #143420)

Andrzej WarzyƄski llvmlistbot at llvm.org
Wed Jun 11 08:09:14 PDT 2025


================
@@ -54,6 +54,33 @@ static SmallVector<Value> sliceTransferIndices(ArrayRef<int64_t> elementOffsets,
   return slicedIndices;
 }
 
+// Compute the new indices for vector.load/store by adding `offsets` to
+// `originalIndices`.
+// It assumes m <= n (m = offsets.size(), n = originalIndices.size())
+// Last m of `originalIndices` will be updated.
+static SmallVector<Value> computeIndices(PatternRewriter &rewriter,
+                                         Location loc,
+                                         ArrayRef<Value> originalIndices,
+                                         ArrayRef<int64_t> offsets) {
+  assert(offsets.size() <= originalIndices.size() &&
+         "Offsets should not exceed the number of original indices");
+  SmallVector<Value> indices(originalIndices);
+  auto originalIter = originalIndices.rbegin();
+  auto offsetsIter = offsets.rbegin();
+  auto indicesIter = indices.rbegin();
+  while (offsetsIter != offsets.rend()) {
+    Value original = *originalIter;
+    int64_t offset = *offsetsIter;
+    if (offset != 0)
+      *indicesIter = rewriter.create<arith::AddIOp>(
+          loc, original, rewriter.create<arith::ConstantIndexOp>(loc, offset));
+    originalIter++;
+    offsetsIter++;
+    indicesIter++;
+  }
----------------
banach-space wrote:

This is quite verbose. Also, I'm not sure why you iterate from the end. 

Have you considered using `llvm::zip` or `llvm::enumerate`? Things like `ArrayRef::drop_front` might also be helpful. 

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


More information about the Mlir-commits mailing list