[Mlir-commits] [mlir] [mlir][linalg] Add support for masked vectorization of `tensor.insert_slice` (1/N) (PR #122927)

Andrzej WarzyƄski llvmlistbot at llvm.org
Wed Jan 22 08:36:49 PST 2025


================
@@ -2583,113 +2626,139 @@ static Value getStaticPadVal(Operation *op) {
   return {};
 }
 
-/// Rewrite tensor.insert.slice as a vector.transfer_read +
-/// vector.transfer_write pair. The vector size is inferred from the static
-/// dims in the input and output tensors. If a dim is dynamic in both the input
-/// and output tensors, bails out.
-///
-/// Before:
-///     !t_in_type = tensor<1x2x3xf32>
-///     !t_out_type = tensor<9x8x7x1x2x3xf32>
-///     !v_type = vector<1x2x3xf32>
-///     %inserted_slice = tensor.insert_slice %src into %dest ... : !t_in_type
-///     into !t_out_type
-/// After:
-///     %read = vector.transfer_read %src[...], %pad ... : !t_in_type, !v_type
-///     %write = vector.transfer_write %read, %dest ... : !v_type, !t_out_type
-///
-/// TODO: Support masking
-struct InsertSliceVectorizePattern
-    : public OpRewritePattern<tensor::InsertSliceOp> {
-  using OpRewritePattern<tensor::InsertSliceOp>::OpRewritePattern;
+static LogicalResult
+vectorizeAsInsertSliceOp(RewriterBase &rewriter, tensor::InsertSliceOp sliceOp,
+                         ArrayRef<int64_t> inputVectorSizes,
+                         SmallVectorImpl<Value> &newResults) {
+  // TODO: Introduce a parent class that will handle the insertion point update.
----------------
banach-space wrote:

All these patterns do exactly the same:
* [vectorizeAsTensorPackOp](https://github.com/llvm/llvm-project/blob/d839c06719128700bdd033361b20aa6899f6620a/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp#L1560)
* [vectorizeAsTensorUnpackOp](https://github.com/llvm/llvm-project/blob/d839c06719128700bdd033361b20aa6899f6620a/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp#L1636)
* [vectorizeAsTensorPadOp](https://github.com/llvm/llvm-project/blob/d839c06719128700bdd033361b20aa6899f6620a/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp#L1767)

We may as well just wrap this into a parent class.

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


More information about the Mlir-commits mailing list