[Mlir-commits] [mlir] 7ad566d - [mlir] Fix `remove-dead-values` pass throws error when module has a name (#109990)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Oct 3 01:51:59 PDT 2024
Author: Perry Gibson
Date: 2024-10-03T10:51:55+02:00
New Revision: 7ad566d575b9a3657f2bfd37005ef475154dd86d
URL: https://github.com/llvm/llvm-project/commit/7ad566d575b9a3657f2bfd37005ef475154dd86d
DIFF: https://github.com/llvm/llvm-project/commit/7ad566d575b9a3657f2bfd37005ef475154dd86d.diff
LOG: [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.
Added:
Modified:
mlir/lib/Transforms/RemoveDeadValues.cpp
mlir/test/Transforms/remove-dead-values.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Transforms/RemoveDeadValues.cpp b/mlir/lib/Transforms/RemoveDeadValues.cpp
index 1cc0096805616c..3de4fb75ed831c 100644
--- a/mlir/lib/Transforms/RemoveDeadValues.cpp
+++ b/mlir/lib/Transforms/RemoveDeadValues.cpp
@@ -576,6 +576,8 @@ void RemoveDeadValues::runOnOperation() {
// all symbol ops present in the IR are function-like, and all symbol user ops
// present in the IR are call-like.
WalkResult acceptableIR = module->walk([&](Operation *op) {
+ if (op == module)
+ return WalkResult::advance();
if (isa<BranchOpInterface>(op) ||
(isa<SymbolOpInterface>(op) && !isa<FunctionOpInterface>(op)) ||
(isa<SymbolUserOpInterface>(op) && !isa<CallOpInterface>(op))) {
diff --git a/mlir/test/Transforms/remove-dead-values.mlir b/mlir/test/Transforms/remove-dead-values.mlir
index a31cb97cb57125..9f2be3331b6b4b 100644
--- a/mlir/test/Transforms/remove-dead-values.mlir
+++ b/mlir/test/Transforms/remove-dead-values.mlir
@@ -1,13 +1,25 @@
// RUN: mlir-opt %s -remove-dead-values -split-input-file -verify-diagnostics | FileCheck %s
// The IR remains untouched because of the presence of a non-function-like
-// symbol op (module @dont_touch_unacceptable_ir).
+// symbol op inside the module (const @__dont_touch_unacceptable_ir).
//
+module {
// expected-error @+1 {{cannot optimize an IR with non-function symbol ops, non-call symbol user ops or branch ops}}
-module @dont_touch_unacceptable_ir {
- func.func @has_cleanable_simple_op(%arg0 : i32) {
- %non_live = arith.addi %arg0, %arg0 : i32
- return
+ memref.global "private" constant @__dont_touch_unacceptable_ir : memref<i32> = dense<0>
+ func.func @main(%arg0: i32) -> i32 {
+ return %arg0 : i32
+ }
+}
+
+// -----
+
+// Dead values are removed from the IR even if the module has a name
+//
+module @named_module_acceptable {
+ func.func @main(%arg0: tensor<10xf32>) -> tensor<10xf32> {
+ %0 = tensor.empty() : tensor<10xbf16>
+ // CHECK-NOT: tensor.empty
+ return %arg0 : tensor<10xf32>
}
}
More information about the Mlir-commits
mailing list