diff --git a/mlir/include/mlir/Dialect/Vector/VectorOps.td b/mlir/include/mlir/Dialect/Vector/VectorOps.td --- a/mlir/include/mlir/Dialect/Vector/VectorOps.td +++ b/mlir/include/mlir/Dialect/Vector/VectorOps.td @@ -851,6 +851,8 @@ return dest().getType().cast(); } }]; + + let hasFolder = 1; } def Vector_OuterProductOp : diff --git a/mlir/lib/Dialect/Vector/VectorOps.cpp b/mlir/lib/Dialect/Vector/VectorOps.cpp --- a/mlir/lib/Dialect/Vector/VectorOps.cpp +++ b/mlir/lib/Dialect/Vector/VectorOps.cpp @@ -1796,6 +1796,12 @@ return success(); } +OpFoldResult InsertStridedSliceOp::fold(ArrayRef operands) { + if (getSourceVectorType() == getDestVectorType()) + return source(); + return {}; +} + //===----------------------------------------------------------------------===// // OuterProductOp //===----------------------------------------------------------------------===// diff --git a/mlir/test/Dialect/Vector/canonicalize.mlir b/mlir/test/Dialect/Vector/canonicalize.mlir --- a/mlir/test/Dialect/Vector/canonicalize.mlir +++ b/mlir/test/Dialect/Vector/canonicalize.mlir @@ -1037,3 +1037,13 @@ // CHECK: return %[[v]] : vector<2xf32> return %0 : vector<2xf32> } + +// ----- + +// CHECK-LABEL: func @insert_strided_slice_full_range +// CHECK-SAME: %[[SOURCE:.+]]: vector<16x16xf16>, %{{.+}}: vector<16x16xf16> +func @insert_strided_slice_full_range(%source: vector<16x16xf16>, %dest: vector<16x16xf16>) -> vector<16x16xf16> { + %0 = vector.insert_strided_slice %source, %dest {offsets = [0, 0], strides = [1, 1]} : vector<16x16xf16> into vector<16x16xf16> + // CHECK: return %[[SOURCE]] + return %0: vector<16x16xf16> +} diff --git a/mlir/test/Dialect/Vector/vector-transforms.mlir b/mlir/test/Dialect/Vector/vector-transforms.mlir --- a/mlir/test/Dialect/Vector/vector-transforms.mlir +++ b/mlir/test/Dialect/Vector/vector-transforms.mlir @@ -441,10 +441,11 @@ } // CHECK-LABEL: func @cast_away_insert_strided_slice_leading_one_dims_one_element +// CHECK-SAME: %[[ARG0:.+]]: vector<1x1xf16>, %{{.+}}: vector<1x1x1xf16> func @cast_away_insert_strided_slice_leading_one_dims_one_element(%arg0: vector<1x1xf16>, %arg1: vector<1x1x1xf16>) -> vector<1x1x1xf16> { - // CHECK: vector.shape_cast %{{.+}} : vector<1x1xf16> to vector<1xf16> - // CHECK: vector.shape_cast %{{.+}} : vector<1x1x1xf16> to vector<1xf16> + // CHECK: %[[CAST:.+]] = vector.shape_cast %[[ARG0]] : vector<1x1xf16> to vector<1x1x1xf16> %0 = vector.insert_strided_slice %arg0, %arg1 {offsets = [0, 0, 0], strides = [1, 1]} : vector<1x1xf16> into vector<1x1x1xf16> + // CHECK: return %[[CAST]] return %0: vector<1x1x1xf16> }