[Mlir-commits] [mlir] [MLIR][TOSA] Add tosa.slice operation conversion failure scenario (PR #68578)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Oct 9 04:49:59 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

<details>
<summary>Changes</summary>

Fixes #<!-- -->68481, if the resultType of tosa.slice is UnrankedTensorType, Coversion  fails

---
Full diff: https://github.com/llvm/llvm-project/pull/68578.diff


2 Files Affected:

- (modified) mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp (+3) 
- (added) mlir/test/Conversion/TosaToTensor/tosa-to-tensor-invalid.mlir (+8) 


``````````diff
diff --git a/mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp b/mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp
index f51ada8d08b5edd..06ec53d19b1e956 100644
--- a/mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp
+++ b/mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp
@@ -243,6 +243,9 @@ 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))
+      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..d53b2e9fb91bba7
--- /dev/null
+++ b/mlir/test/Conversion/TosaToTensor/tosa-to-tensor-invalid.mlir
@@ -0,0 +1,8 @@
+// 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>
+}
\ No newline at end of file

``````````

</details>


https://github.com/llvm/llvm-project/pull/68578


More information about the Mlir-commits mailing list