[Mlir-commits] [mlir] [mlir] Fix `remove-dead-values` pass throws error when module has a name (PR #109990)

Perry Gibson llvmlistbot at llvm.org
Thu Sep 26 01:46:31 PDT 2024


https://github.com/Wheest updated https://github.com/llvm/llvm-project/pull/109990

>From eeba53c4d7b815268882ce8d1ed65e9736ef10b9 Mon Sep 17 00:00:00 2001
From: pez <perry at gibsonic.org>
Date: Wed, 25 Sep 2024 15:22:56 +0100
Subject: [PATCH 1/2] Fix remove-dead-values throws error w/module name

https://github.com/llvm/llvm-project/issues/107870
---
 mlir/lib/Transforms/RemoveDeadValues.cpp     |  2 ++
 mlir/test/Transforms/remove-dead-values.mlir | 15 ++++++++-------
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/mlir/lib/Transforms/RemoveDeadValues.cpp b/mlir/lib/Transforms/RemoveDeadValues.cpp
index 055256903a1522..287273ce74e2f5 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 69426fdb620832..4622b6afa942de 100644
--- a/mlir/test/Transforms/remove-dead-values.mlir
+++ b/mlir/test/Transforms/remove-dead-values.mlir
@@ -1,13 +1,14 @@
 // 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).
+// -----
+
+// Dead values are removed from the IR even if the module has a name
 //
-// 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
+module @named_module_acceptable {
+  func.func @main(%arg0: tensor<10xf32>) -> tensor<10xf32> {
+    %0 = tensor.empty() : tensor<10xbf16>
+    // CHECK-NOT: %[[C:.*]] = tensor.empty[[C:.*]]
+    return %arg0 : tensor<10xf32>
   }
 }
 

>From 94b7dd4b748f59d018e2735ae83dd33748334f30 Mon Sep 17 00:00:00 2001
From: pez <perry at gibsonic.org>
Date: Thu, 26 Sep 2024 09:45:39 +0100
Subject: [PATCH 2/2] Test for non-function symbol op inside the module

---
 mlir/test/Transforms/remove-dead-values.mlir | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/mlir/test/Transforms/remove-dead-values.mlir b/mlir/test/Transforms/remove-dead-values.mlir
index 4622b6afa942de..1b3f06874945c0 100644
--- a/mlir/test/Transforms/remove-dead-values.mlir
+++ b/mlir/test/Transforms/remove-dead-values.mlir
@@ -1,5 +1,16 @@
 // 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).
+//
+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 {
+    return %arg0 : i32
+  }
+}
+
 // -----
 
 // Dead values are removed from the IR even if the module has a name



More information about the Mlir-commits mailing list