[mlir][vector] Add folder for no-op InsertStridedSliceOp

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D111636
This commit is contained in:
Lei Zhang 2021-10-12 11:39:56 -04:00
parent 55e76c70a4
commit 519b350de0
4 changed files with 21 additions and 2 deletions

View File

@ -851,6 +851,8 @@ def Vector_InsertStridedSliceOp :
return dest().getType().cast<VectorType>();
}
}];
let hasFolder = 1;
}
def Vector_OuterProductOp :

View File

@ -1796,6 +1796,12 @@ static LogicalResult verify(InsertStridedSliceOp op) {
return success();
}
OpFoldResult InsertStridedSliceOp::fold(ArrayRef<Attribute> operands) {
if (getSourceVectorType() == getDestVectorType())
return source();
return {};
}
//===----------------------------------------------------------------------===//
// OuterProductOp
//===----------------------------------------------------------------------===//

View File

@ -1037,3 +1037,13 @@ func @vector_multi_reduction_single_parallel(%arg0: vector<2xf32>) -> vector<2xf
// 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>
}

View File

@ -441,10 +441,11 @@ func @cast_away_insert_strided_slice_leading_one_dims(%arg0: vector<1x8xf16>, %a
}
// 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>
}