Skip to content

[MLIR] RemoveDeadValues: Allowing IRs with global constants to get dead values removed #116519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions mlir/lib/Transforms/RemoveDeadValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This last check is also not clear to me. But I'm not sure if this has all to do with some aspects of the dataflow framework?

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();
}
Expand Down
10 changes: 5 additions & 5 deletions mlir/test/Transforms/remove-dead-values.mlir
Original file line number Diff line number Diff line change
@@ -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
}
}
Expand All @@ -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
Expand Down
Loading