Skip to content

Commit 24ced77

Browse files
authored
[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 <[email protected]>
1 parent 8f50321 commit 24ced77

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

mlir/lib/Transforms/RemoveDeadValues.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -573,15 +573,13 @@ void RemoveDeadValues::runOnOperation() {
573573
Operation *module = getOperation();
574574

575575
// The removal of non-live values is performed iff there are no branch ops,
576-
// all symbol ops present in the IR are function-like, and all symbol user ops
577-
// present in the IR are call-like.
576+
// and all symbol user ops present in the IR are call-like.
578577
WalkResult acceptableIR = module->walk([&](Operation *op) {
579578
if (op == module)
580579
return WalkResult::advance();
581580
if (isa<BranchOpInterface>(op) ||
582-
(isa<SymbolOpInterface>(op) && !isa<FunctionOpInterface>(op)) ||
583581
(isa<SymbolUserOpInterface>(op) && !isa<CallOpInterface>(op))) {
584-
op->emitError() << "cannot optimize an IR with non-function symbol ops, "
582+
op->emitError() << "cannot optimize an IR with "
585583
"non-call symbol user ops or branch ops\n";
586584
return WalkResult::interrupt();
587585
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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 inside the module (const @__dont_touch_unacceptable_ir).
3+
// The IR is updated regardless of memref.global private constant
54
//
65
module {
7-
// expected-error @+1 {{cannot optimize an IR with non-function symbol ops, non-call symbol user ops or branch ops}}
8-
memref.global "private" constant @__dont_touch_unacceptable_ir : memref<i32> = dense<0>
6+
memref.global "private" constant @__something_global : memref<i32> = dense<0>
97
func.func @main(%arg0: i32) -> i32 {
8+
%0 = tensor.empty() : tensor<10xbf16>
9+
// CHECK-NOT: tensor.empty
1010
return %arg0 : i32
1111
}
1212
}
@@ -29,7 +29,7 @@ module @named_module_acceptable {
2929
//
3030
func.func @dont_touch_unacceptable_ir_has_cleanable_simple_op_with_branch_op(%arg0: i1) {
3131
%non_live = arith.constant 0 : i32
32-
// expected-error @+1 {{cannot optimize an IR with non-function symbol ops, non-call symbol user ops or branch ops}}
32+
// expected-error @+1 {{cannot optimize an IR with non-call symbol user ops or branch ops}}
3333
cf.cond_br %arg0, ^bb1(%non_live : i32), ^bb2(%non_live : i32)
3434
^bb1(%non_live_0 : i32):
3535
cf.br ^bb3

0 commit comments

Comments
 (0)