[Mlir-commits] [mlir] [MLIR] Add pattern to fold insert_slice of extract_slice (PR #86328)
Jerry Wu
llvmlistbot at llvm.org
Wed Mar 27 10:23:12 PDT 2024
================
@@ -142,11 +142,15 @@ mlir::tensor::getUnPackInverseSrcPerm(UnPackOp unpackOp,
bool mlir::tensor::isCastLikeInsertSliceOp(InsertSliceOp op) {
llvm::SmallBitVector droppedDims = op.getDroppedDims();
int64_t srcDim = 0;
+ RankedTensorType resultType = op.getDestType();
// Source dims and destination dims (apart from dropped dims) must have the
// same size.
- for (int64_t resultDim = 0; resultDim < op.getDestType().getRank();
- ++resultDim) {
+ for (int64_t resultDim = 0; resultDim < resultType.getRank(); ++resultDim) {
if (droppedDims.test(resultDim)) {
+ // InsertSlice may expand unit dimensions that result from inserting a
+ // size-1 slice into a non-size-1 result dimension.
+ if (resultType.getDimSize(resultDim) != 1)
----------------
pzread wrote:
This is to check if the dropped unit dim is inserted into non-unit dim. For example:
```mlir
tensor.insert_slice %x into %y[0, 0, 0] [1, 8, 8] [1, 1, 1] : tensor<8x8xf32> into tensor<2x8x8xf32>
```
in this case, the first dim of `1x8x8xf32` is considered as the dropped unit dim, but it is inserted into `2x8x8xf32`. I think in this case we don't consider it as a cast-like op as the source `(1)x8x8xf32` != the destination `2x8x8xf32`
https://github.com/llvm/llvm-project/pull/86328
More information about the Mlir-commits
mailing list