Skip to content

Commit 6d6e67a

Browse files
committed
[MLIR][TOSA] Add tosa.slice operation conversion failure scenario
Fixes #68481, In the following scenario, the conversion fails: 1. resultType of tosa.slice is UnrankedTensorType 2. tosa.slice.getsize().size() < resultType.getRank()
1 parent efb11c4 commit 6d6e67a

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ class SliceConverter : public OpConversionPattern<tosa::SliceOp> {
243243
ConversionPatternRewriter &rewriter) const final {
244244
Location loc = sliceOp.getLoc();
245245
Value input = adaptor.getInput();
246+
ShapedType resultType = cast<ShapedType>(sliceOp.getType());
247+
if (llvm::isa<UnrankedTensorType>(resultType) ||
248+
resultType.getRank() != static_cast<int64_t>(sliceOp.getSize().size()))
249+
return failure();
246250
SmallVector<int64_t> strides, sizes;
247251
ArrayRef<int64_t> starts = sliceOp.getStart();
248252
strides.resize(cast<ShapedType>(sliceOp.getType()).getRank(), 1);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: mlir-opt --split-input-file -pass-pipeline="builtin.module(func.func(tosa-to-tensor))" %s -verify-diagnostics
2+
3+
// CHECK-LABEL: @slice_resultType_unranked
4+
func.func @slice_resultType_unranked(%arg0: tensor<?xf32>) -> (tensor<*xf32>) {
5+
// expected-error@+1 {{failed to legalize operation 'tosa.slice'}}
6+
%0 = "tosa.slice"(%arg0) {start = array<i64: 2>, size = array<i64: 0>} : (tensor<?xf32>) -> (tensor<*xf32>)
7+
return %0 : tensor<*xf32>
8+
}
9+
10+
// CHECK-LABEL: @slice_resultRank_neq_opSize
11+
func.func @slice_resultRank_neq_opSize(%arg0: tensor<12xf32>) -> (tensor<2xf32>) {
12+
// expected-error@+1 {{failed to legalize operation 'tosa.slice'}}
13+
%0 = "tosa.slice"(%arg0) {start = array<i64: 2>, size = array<i64: 2, 3>} : (tensor<12xf32>) -> (tensor<2xf32>)
14+
return %0 : tensor<2xf32>
15+
}

0 commit comments

Comments
 (0)