[Mlir-commits] [mlir] [mlir][vector] Drop innermost unit dims on transfer_write. (PR #78554)
Andrzej WarzyĆski
llvmlistbot at llvm.org
Thu Jan 18 10:38:20 PST 2024
================
@@ -1152,8 +1152,71 @@ struct FoldI1Select : public OpRewritePattern<arith::SelectOp> {
}
};
-// Drop inner most contiguous unit dimensions from transfer_read operand.
-class DropInnerMostUnitDims : public OpRewritePattern<vector::TransferReadOp> {
+/// Returns the number of dims can be folded away from transfer ops. It returns
+/// a failure if strides and offsets can not be resolved.
+static FailureOr<size_t>
+getTransferFoldableInnerUnitDims(MemRefType srcType, VectorType vectorType) {
+ SmallVector<int64_t> srcStrides;
+ int64_t srcOffset;
+ if (failed(getStridesAndOffset(srcType, srcStrides, srcOffset)))
+ return failure();
+
+ // According to vector.transfer_read/write semantics, the vector can be a
+ // slice. It pads the indices with `1` starting from beginning. Thus, we have
+ // to offset the check index with `rankDiff` in `srcStrides` and source dim
+ // sizes.
+ size_t result = 0;
+ int rankDiff = srcType.getRank() - vectorType.getRank();
+ for (int64_t i = 0, e = vectorType.getRank(); i < e; ++i) {
+ // Check that the inner dim size is 1 for both memref/tensor type and
----------------
banach-space wrote:
[nit] This method won't work for tensors :)
```suggestion
// Check that the inner dim size is 1 for both memref type and
```
https://github.com/llvm/llvm-project/pull/78554
More information about the Mlir-commits
mailing list