Skip to content

Commit 7ad566d

Browse files
authored
[mlir] Fix remove-dead-values pass throws error when module has a name (#109990)
Fixes #107870. We can allow the enclosing Module operation to have a symbol. The check was likely originally not considering this case and intended to catch symbols inside the region, not accounting that the walk would visit the enclosing operation.
1 parent 612760e commit 7ad566d

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

mlir/lib/Transforms/RemoveDeadValues.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,8 @@ void RemoveDeadValues::runOnOperation() {
576576
// all symbol ops present in the IR are function-like, and all symbol user ops
577577
// present in the IR are call-like.
578578
WalkResult acceptableIR = module->walk([&](Operation *op) {
579+
if (op == module)
580+
return WalkResult::advance();
579581
if (isa<BranchOpInterface>(op) ||
580582
(isa<SymbolOpInterface>(op) && !isa<FunctionOpInterface>(op)) ||
581583
(isa<SymbolUserOpInterface>(op) && !isa<CallOpInterface>(op))) {

mlir/test/Transforms/remove-dead-values.mlir

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
// RUN: mlir-opt %s -remove-dead-values -split-input-file -verify-diagnostics | FileCheck %s
22

33
// The IR remains untouched because of the presence of a non-function-like
4-
// symbol op (module @dont_touch_unacceptable_ir).
4+
// symbol op inside the module (const @__dont_touch_unacceptable_ir).
55
//
6+
module {
67
// expected-error @+1 {{cannot optimize an IR with non-function symbol ops, non-call symbol user ops or branch ops}}
7-
module @dont_touch_unacceptable_ir {
8-
func.func @has_cleanable_simple_op(%arg0 : i32) {
9-
%non_live = arith.addi %arg0, %arg0 : i32
10-
return
8+
memref.global "private" constant @__dont_touch_unacceptable_ir : memref<i32> = dense<0>
9+
func.func @main(%arg0: i32) -> i32 {
10+
return %arg0 : i32
11+
}
12+
}
13+
14+
// -----
15+
16+
// Dead values are removed from the IR even if the module has a name
17+
//
18+
module @named_module_acceptable {
19+
func.func @main(%arg0: tensor<10xf32>) -> tensor<10xf32> {
20+
%0 = tensor.empty() : tensor<10xbf16>
21+
// CHECK-NOT: tensor.empty
22+
return %arg0 : tensor<10xf32>
1123
}
1224
}
1325

0 commit comments

Comments
 (0)