[Mlir-commits] [mlir] [MLIR][Vector] Add unroll pattern for vector.shape_cast (PR #164010)

Jakub Kuderski llvmlistbot at llvm.org
Sat Oct 18 12:16:55 PDT 2025


================
@@ -75,6 +75,54 @@ static SmallVector<Value> sliceLoadStoreIndices(PatternRewriter &rewriter,
   return indices;
 }
 
+/// Creates a result tile by extracting individual elements from the source
+/// and inserting them at the correct positions in the tile.
+static Value createTileFromElements(PatternRewriter &rewriter, Location loc,
+                                    Value source, ArrayRef<int64_t> sourceShape,
+                                    ArrayRef<int64_t> resultShape,
+                                    ArrayRef<int64_t> tileOffsets,
+                                    ArrayRef<int64_t> tileShape,
+                                    VectorType tileType) {
+
+  // Initialize tile with zeros.
+  Value tile = rewriter.create<arith::ConstantOp>(
+      loc, tileType, rewriter.getZeroAttr(tileType));
+
+  // Calculate strides for both source and result shapes.
+  SmallVector<int64_t> sourceStrides = computeStrides(sourceShape);
+  SmallVector<int64_t> resultStrides = computeStrides(resultShape);
+
+  // Iterate over all positions in the tile using linear indexing.
+  for (int64_t linearTileIdx = 0; linearTileIdx < computeProduct(tileShape);
----------------
kuhar wrote:

Avoid repeated calculation in the loop contion

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


More information about the Mlir-commits mailing list