Skip to content

Commit 49a4ec2

Browse files
authored
[mlir] Reland the dialect conversion hanging use fix (#87297)
Dialect conversion sometimes can have a hanging use of an argument. Ensured that argument uses are dropped before removing the block.
1 parent 9067f54 commit 49a4ec2

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

mlir/lib/Transforms/Utils/DialectConversion.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ class CreateBlockRewrite : public BlockRewrite {
279279
auto &blockOps = block->getOperations();
280280
while (!blockOps.empty())
281281
blockOps.remove(blockOps.begin());
282+
for (auto arg : block->getArguments())
283+
arg.dropAllUses();
282284
block->dropAllUses();
283285
if (block->getParent())
284286
block->erase();

mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-invalid.mlir

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,16 @@ func.func @tensor_with_unknown_rank(%arg0: tensor<*xi8>) -> tensor<*xi8> {
1515
%0 = "tosa.abs"(%arg0) : (tensor<*xi8>) -> tensor<*xi8>
1616
return %0 : tensor<*xi8>
1717
}
18+
19+
// -----
20+
21+
// CHECK-LABEL: @unranked_add
22+
func.func @unranked_add(%arg0 : tensor<10x10xf32> , %arg1 : tensor<10x10xf32>, %arg2 : tensor<*xf32>) -> (tensor<10x10xf32>) {
23+
// expected-error@+3 {{failed to legalize operation 'tosa.add'}}
24+
%reduce = tosa.reduce_max %arg0 {axis = 1 : i32} : (tensor<10x10xf32>) -> tensor<10x1xf32>
25+
%1 = tosa.add %reduce, %arg1 : (tensor<10x1xf32>, tensor<10x10xf32>) -> tensor<10x10xf32>
26+
%0 = tosa.add %1, %arg2 : (tensor<10x10xf32>, tensor<*xf32>) -> tensor<*xf32>
27+
%2 = tosa.reshape %0 {new_shape = array<i64: 10, 10>} : (tensor<*xf32>) -> tensor<10x10xf32>
28+
return %2 : tensor<10x10xf32>
29+
}
30+

0 commit comments

Comments
 (0)