Skip to content

Commit eeba53c

Browse files
committed
Fix remove-dead-values throws error w/module name
#107870
1 parent 547917a commit eeba53c

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
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: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// RUN: mlir-opt %s -remove-dead-values -split-input-file -verify-diagnostics | FileCheck %s
22

3-
// The IR remains untouched because of the presence of a non-function-like
4-
// symbol op (module @dont_touch_unacceptable_ir).
3+
// -----
4+
5+
// Dead values are removed from the IR even if the module has a name
56
//
6-
// 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
7+
module @named_module_acceptable {
8+
func.func @main(%arg0: tensor<10xf32>) -> tensor<10xf32> {
9+
%0 = tensor.empty() : tensor<10xbf16>
10+
// CHECK-NOT: %[[C:.*]] = tensor.empty[[C:.*]]
11+
return %arg0 : tensor<10xf32>
1112
}
1213
}
1314

0 commit comments

Comments
 (0)