[Mlir-commits] [mlir] [MLIR] RemoveDeadValues: Allowing IRs with global constants to get dead values removed (PR #116519)
Renat Idrisov
llvmlistbot at llvm.org
Mon Nov 18 14:56:14 PST 2024
https://github.com/parsifal-47 updated https://github.com/llvm/llvm-project/pull/116519
>From 0247d1b5d19b892c95649da0a485b7ad17bbd8ac Mon Sep 17 00:00:00 2001
From: Renat Idrisov <parsifal-47 at users.noreply.github.com>
Date: Sat, 16 Nov 2024 21:16:25 +0000
Subject: [PATCH 1/2] Allowing IRs with global constants to get dead values
removed
---
mlir/lib/Transforms/RemoveDeadValues.cpp | 1 -
mlir/test/Transforms/remove-dead-values.mlir | 6 +++---
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/mlir/lib/Transforms/RemoveDeadValues.cpp b/mlir/lib/Transforms/RemoveDeadValues.cpp
index 7e45f18b660ba7..edfb1969ab75c7 100644
--- a/mlir/lib/Transforms/RemoveDeadValues.cpp
+++ b/mlir/lib/Transforms/RemoveDeadValues.cpp
@@ -579,7 +579,6 @@ void RemoveDeadValues::runOnOperation() {
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, "
"non-call symbol user ops or branch ops\n";
diff --git a/mlir/test/Transforms/remove-dead-values.mlir b/mlir/test/Transforms/remove-dead-values.mlir
index 9f2be3331b6b4b..b06b3320706cc8 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>
func.func @main(%arg0: i32) -> i32 {
+ %0 = tensor.empty() : tensor<10xbf16>
+ // CHECK-NOT: tensor.empty
return %arg0 : i32
}
}
>From c145899e5439bf2acd3a66013316c1915c63f98b Mon Sep 17 00:00:00 2001
From: Renat Idrisov <parsifal-47 at users.noreply.github.com>
Date: Mon, 18 Nov 2024 14:55:59 -0800
Subject: [PATCH 2/2] Address feedback from Code Review
---
mlir/lib/Transforms/RemoveDeadValues.cpp | 5 ++---
mlir/test/Transforms/remove-dead-values.mlir | 4 ++--
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/mlir/lib/Transforms/RemoveDeadValues.cpp b/mlir/lib/Transforms/RemoveDeadValues.cpp
index edfb1969ab75c7..b82280dda8ba73 100644
--- a/mlir/lib/Transforms/RemoveDeadValues.cpp
+++ b/mlir/lib/Transforms/RemoveDeadValues.cpp
@@ -573,14 +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<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 b06b3320706cc8..47137fc6430fea 100644
--- a/mlir/test/Transforms/remove-dead-values.mlir
+++ b/mlir/test/Transforms/remove-dead-values.mlir
@@ -3,7 +3,7 @@
// The IR is updated regardless of memref.global private constant
//
module {
- 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
@@ -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