[Mlir-commits] [mlir] 519b350 - [mlir][vector] Add folder for no-op InsertStridedSliceOp
Lei Zhang
llvmlistbot at llvm.org
Tue Oct 12 08:44:42 PDT 2021
Author: Lei Zhang
Date: 2021-10-12T11:41:35-04:00
New Revision: 519b350de062a6118629e554c9e00c9ff9ef204e
URL: https://github.com/llvm/llvm-project/commit/519b350de062a6118629e554c9e00c9ff9ef204e
DIFF: https://github.com/llvm/llvm-project/commit/519b350de062a6118629e554c9e00c9ff9ef204e.diff
LOG: [mlir][vector] Add folder for no-op InsertStridedSliceOp
Reviewed By: nicolasvasilache
Differential Revision: https://reviews.llvm.org/D111636
Added:
Modified:
mlir/include/mlir/Dialect/Vector/VectorOps.td
mlir/lib/Dialect/Vector/VectorOps.cpp
mlir/test/Dialect/Vector/canonicalize.mlir
mlir/test/Dialect/Vector/vector-transforms.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/Vector/VectorOps.td b/mlir/include/mlir/Dialect/Vector/VectorOps.td
index cdd5fcdbc548..7302f6ad7b57 100644
--- a/mlir/include/mlir/Dialect/Vector/VectorOps.td
+++ b/mlir/include/mlir/Dialect/Vector/VectorOps.td
@@ -851,6 +851,8 @@ def Vector_InsertStridedSliceOp :
return dest().getType().cast<VectorType>();
}
}];
+
+ let hasFolder = 1;
}
def Vector_OuterProductOp :
diff --git a/mlir/lib/Dialect/Vector/VectorOps.cpp b/mlir/lib/Dialect/Vector/VectorOps.cpp
index e696f3481ed0..31c538a7fd4e 100644
--- a/mlir/lib/Dialect/Vector/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/VectorOps.cpp
@@ -1796,6 +1796,12 @@ static LogicalResult verify(InsertStridedSliceOp op) {
return success();
}
+OpFoldResult InsertStridedSliceOp::fold(ArrayRef<Attribute> operands) {
+ if (getSourceVectorType() == getDestVectorType())
+ return source();
+ return {};
+}
+
//===----------------------------------------------------------------------===//
// OuterProductOp
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/Dialect/Vector/canonicalize.mlir b/mlir/test/Dialect/Vector/canonicalize.mlir
index f713ac38ce76..d98c4ea6a603 100644
--- a/mlir/test/Dialect/Vector/canonicalize.mlir
+++ b/mlir/test/Dialect/Vector/canonicalize.mlir
@@ -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>
+}
diff --git a/mlir/test/Dialect/Vector/vector-transforms.mlir b/mlir/test/Dialect/Vector/vector-transforms.mlir
index c925b8e1c76e..1686079fa34b 100644
--- a/mlir/test/Dialect/Vector/vector-transforms.mlir
+++ b/mlir/test/Dialect/Vector/vector-transforms.mlir
@@ -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>
}
More information about the Mlir-commits
mailing list