[Mlir-commits] [mlir] 9ab732f - [MLIR][TOSA] Add tosa.slice operation conversion failure scenario (#68578)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Oct 9 20:39:28 PDT 2023
Author: LiqinWeng
Date: 2023-10-10T11:39:25+08:00
New Revision: 9ab732f630de94aeac47d95a8d1e6093f432506e
URL: https://github.com/llvm/llvm-project/commit/9ab732f630de94aeac47d95a8d1e6093f432506e
DIFF: https://github.com/llvm/llvm-project/commit/9ab732f630de94aeac47d95a8d1e6093f432506e.diff
LOG: [MLIR][TOSA] Add tosa.slice operation conversion failure scenario (#68578)
Fixes #68481, In the following scenario, the conversion fails:
1. resultType of tosa.slice is UnrankedTensorType
2. tosa.slice.getsize().size() < resultType.getRank()
Added:
mlir/test/Conversion/TosaToTensor/tosa-to-tensor-invalid.mlir
Modified:
mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp b/mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp
index f51ada8d08b5edd..7a62429d3700443 100644
--- a/mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp
+++ b/mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp
@@ -243,6 +243,10 @@ class SliceConverter : public OpConversionPattern<tosa::SliceOp> {
ConversionPatternRewriter &rewriter) const final {
Location loc = sliceOp.getLoc();
Value input = adaptor.getInput();
+ ShapedType resultType = cast<ShapedType>(sliceOp.getType());
+ if (llvm::isa<UnrankedTensorType>(resultType) ||
+ resultType.getRank() != static_cast<int64_t>(sliceOp.getSize().size()))
+ return failure();
SmallVector<int64_t> strides, sizes;
ArrayRef<int64_t> starts = sliceOp.getStart();
strides.resize(cast<ShapedType>(sliceOp.getType()).getRank(), 1);
diff --git a/mlir/test/Conversion/TosaToTensor/tosa-to-tensor-invalid.mlir b/mlir/test/Conversion/TosaToTensor/tosa-to-tensor-invalid.mlir
new file mode 100644
index 000000000000000..cfa1c41f2467985
--- /dev/null
+++ b/mlir/test/Conversion/TosaToTensor/tosa-to-tensor-invalid.mlir
@@ -0,0 +1,15 @@
+// RUN: mlir-opt --split-input-file -pass-pipeline="builtin.module(func.func(tosa-to-tensor))" %s -verify-diagnostics
+
+// CHECK-LABEL: @slice_resultType_unranked
+func.func @slice_resultType_unranked(%arg0: tensor<?xf32>) -> (tensor<*xf32>) {
+ // expected-error at +1 {{failed to legalize operation 'tosa.slice'}}
+ %0 = "tosa.slice"(%arg0) {start = array<i64: 2>, size = array<i64: 0>} : (tensor<?xf32>) -> (tensor<*xf32>)
+ return %0 : tensor<*xf32>
+}
+
+// CHECK-LABEL: @slice_resultRank_neq_opSize
+func.func @slice_resultRank_neq_opSize(%arg0: tensor<12xf32>) -> (tensor<2xf32>) {
+ // expected-error at +1 {{failed to legalize operation 'tosa.slice'}}
+ %0 = "tosa.slice"(%arg0) {start = array<i64: 2>, size = array<i64: 2, 3>} : (tensor<12xf32>) -> (tensor<2xf32>)
+ return %0 : tensor<2xf32>
+}
More information about the Mlir-commits
mailing list