[Mlir-commits] [mlir] [mlir]Fix dialect conversion drop uses (PR #86991)
Rob Suderman
llvmlistbot at llvm.org
Fri Mar 29 13:47:17 PDT 2024
https://github.com/rsuderman updated https://github.com/llvm/llvm-project/pull/86991
>From 8fae913aa37e7b584191f82f332c5f2850084da1 Mon Sep 17 00:00:00 2001
From: Rob Suderman <rob.suderman at gmail.com>
Date: Thu, 28 Mar 2024 11:58:34 -0700
Subject: [PATCH 1/2] [mlir][dc] Fix dialect conversion drop uses
Before deleting the block we need to drop uses to the surrounding args.
If this is not performed dialect conversion failures can result in a
failure to remove args (despite the block having no remaining uses).
---
mlir/lib/Transforms/Utils/DialectConversion.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 2ec0b964b304f6a..ef4a636ea124f7b 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -282,8 +282,10 @@ class CreateBlockRewrite : public BlockRewrite {
block->dropAllUses();
if (block->getParent())
block->erase();
- else
+ else {
+ block->dropAllDefinedValueUses();
delete block;
+ }
}
};
>From 631866c26dedf05b51fe02f7357fa60b444f0222 Mon Sep 17 00:00:00 2001
From: Rob Suderman <rob.suderman at gmail.com>
Date: Fri, 29 Mar 2024 13:45:46 -0700
Subject: [PATCH 2/2] Added test to demonstrate crash
---
.../TosaToLinalg/tosa-to-linalg-invalid.mlir | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-invalid.mlir b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-invalid.mlir
index 17eec5936918603..6494e1b27194870 100644
--- a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-invalid.mlir
+++ b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-invalid.mlir
@@ -15,3 +15,16 @@ func.func @tensor_with_unknown_rank(%arg0: tensor<*xi8>) -> tensor<*xi8> {
%0 = "tosa.abs"(%arg0) : (tensor<*xi8>) -> tensor<*xi8>
return %0 : tensor<*xi8>
}
+
+// -----
+
+// CHECK-LABEL: @unranked_add
+func.func @unranked_add(%arg0 : tensor<10x10xf32> , %arg1 : tensor<10x10xf32>, %arg2 : tensor<*xf32>) -> (tensor<10x10xf32>) {
+ // expected-error at +3 {{failed to legalize operation 'tosa.add'}}
+ %reduce = tosa.reduce_max %arg0 {axis = 1 : i32} : (tensor<10x10xf32>) -> tensor<10x1xf32>
+ %1 = tosa.add %reduce, %arg1 : (tensor<10x1xf32>, tensor<10x10xf32>) -> tensor<10x10xf32>
+ %0 = tosa.add %1, %arg2 : (tensor<10x10xf32>, tensor<*xf32>) -> tensor<*xf32>
+ %2 = tosa.reshape %0 {new_shape = array<i64: 10, 10>} : (tensor<*xf32>) -> tensor<10x10xf32>
+ return %2 : tensor<10x10xf32>
+}
+
More information about the Mlir-commits
mailing list