[Mlir-commits] [mlir] 24ced77 - [MLIR] RemoveDeadValues: Allowing IRs with global constants to get dead values removed (#116519)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Nov 22 14:41:34 PST 2024
Author: Renat Idrisov
Date: 2024-11-22T14:41:31-08:00
New Revision: 24ced771cc4eb6ff8429eb085f0ffbef0e906d07
URL: https://github.com/llvm/llvm-project/commit/24ced771cc4eb6ff8429eb085f0ffbef0e906d07
DIFF: https://github.com/llvm/llvm-project/commit/24ced771cc4eb6ff8429eb085f0ffbef0e906d07.diff
LOG: [MLIR] RemoveDeadValues: Allowing IRs with global constants to get dead values removed (#116519)
This change is related to discussion:
https://discourse.llvm.org/t/question-on-criteria-for-acceptable-ir-in-removedeadvaluespass/83131
I do not know the original reason to disallow the optimization on
modules with global private constant. Please let me know what am I
missing, I will be happy to make it better. Thank you!
CC: @Wheest
---------
Co-authored-by: Renat Idrisov <parsifal-47 at users.noreply.github.com>
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 7e45f18b660ba7..b82280dda8ba73 100644
--- a/mlir/lib/Transforms/RemoveDeadValues.cpp
+++ b/mlir/lib/Transforms/RemoveDeadValues.cpp
@@ -573,15 +573,13 @@ void RemoveDeadValues::runOnOperation() {
Operation *module = getOperation();
// The removal of non-live values is performed iff there are no branch ops,
- // all symbol ops present in the IR are function-like, and all symbol user ops
- // present in the IR are call-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))) {
- op->emitError() << "cannot optimize an IR with non-function symbol ops, "
+ op->emitError() << "cannot optimize an IR with "
"non-call symbol user ops or branch ops\n";
return WalkResult::interrupt();
}
diff --git a/mlir/test/Transforms/remove-dead-values.mlir b/mlir/test/Transforms/remove-dead-values.mlir
index 9f2be3331b6b4b..47137fc6430fea 100644
--- a/mlir/test/Transforms/remove-dead-values.mlir
+++ b/mlir/test/Transforms/remove-dead-values.mlir
@@ -1,12 +1,12 @@
// 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 inside the module (const @__dont_touch_unacceptable_ir).
+// The IR is updated regardless of memref.global private constant
//
module {
-// expected-error @+1 {{cannot optimize an IR with non-function symbol ops, non-call symbol user ops or branch ops}}
- memref.global "private" constant @__dont_touch_unacceptable_ir : memref<i32> = dense<0>
+ memref.global "private" constant @__something_global : memref<i32> = dense<0>
func.func @main(%arg0: i32) -> i32 {
+ %0 = tensor.empty() : tensor<10xbf16>
+ // CHECK-NOT: tensor.empty
return %arg0 : i32
}
}
@@ -29,7 +29,7 @@ module @named_module_acceptable {
//
func.func @dont_touch_unacceptable_ir_has_cleanable_simple_op_with_branch_op(%arg0: i1) {
%non_live = arith.constant 0 : i32
- // expected-error @+1 {{cannot optimize an IR with non-function symbol ops, non-call symbol user ops or branch ops}}
+ // expected-error @+1 {{cannot optimize an IR with non-call symbol user ops or branch ops}}
cf.cond_br %arg0, ^bb1(%non_live : i32), ^bb2(%non_live : i32)
^bb1(%non_live_0 : i32):
cf.br ^bb3
More information about the Mlir-commits
mailing list