[Mlir-commits] [mlir] [mlir][Vector] Add a rewrite pattern for gather over a strided memref (PR #72991)

Han-Chung Wang llvmlistbot at llvm.org
Tue Nov 28 10:50:21 PST 2023


================
@@ -96,6 +96,87 @@ struct FlattenGather : OpRewritePattern<vector::GatherOp> {
   }
 };
 
+/// Rewrites a vector.gather of a strided MemRef as a gather of a non-strided
+/// MemRef with updated indices that model the strided access.
+///
+/// ```mlir
+/// %subview = memref.subview %M (...) memref<100x3xf32> to memref<100xf32,
+/// strided<[3]>> %gather = vector.gather %subview (...) : memref<100xf32,
+/// strided<[3]>>
+/// ```
+/// ==>
+/// ```mlir
+/// %collapse_shape = memref.collapse_shape %M (...) memref<100x3xf32> into
+/// memref<300xf32> %1 = arith.muli %idxs, %c3 : vector<4xindex> %gather =
+/// vector.gather %collapse_shape (...) : memref<300xf32> (...)
+/// ```
----------------
hanhanW wrote:

can you format the MLIR snippet a bit? Perhaps we can have one operation per line, e.g.,

```suggestion
/// ```mlir
/// %subview = memref.subview %M (...) memref<100x3xf32> to memref<100xf32,
///     strided<[3]>>
/// %gather = vector.gather %subview (...) : memref<100xf32, strided<[3]>>
/// ```
/// ==>
/// ```mlir
/// %collapse_shape = memref.collapse_shape %M (...) memref<100x3xf32> into
///     memref<300xf32>
/// %1 = arith.muli %idxs, %c3 : vector<4xindex>
/// %gather = vector.gather %collapse_shape (...) : memref<300xf32> (...)
/// ```
```

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


More information about the Mlir-commits mailing list