[Mlir-commits] [mlir] [mlir][transforms] Skip `RemoveDeadValues` for function declaration (PR #108221)

Longsheng Mou llvmlistbot at llvm.org
Wed Sep 11 06:32:15 PDT 2024


https://github.com/CoTinker created https://github.com/llvm/llvm-project/pull/108221

This patch skips `RemoveDeadValues` if funcOp is declaration, which fixes a crash.
Fixes #107546.

>From 03966447f6ecb696ec02367d5789b9e1177ef9a0 Mon Sep 17 00:00:00 2001
From: Longsheng Mou <moulongsheng at huawei.com>
Date: Wed, 11 Sep 2024 21:24:46 +0800
Subject: [PATCH] [mlir][transforms] Skip `RemoveDeadValues` for function
 declaration

This patch skips `RemoveDeadValues` if funcOp is declaration, which
fixes a crash.
---
 mlir/lib/Transforms/RemoveDeadValues.cpp     | 4 ++--
 mlir/test/Transforms/remove-dead-values.mlir | 5 +++++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/mlir/lib/Transforms/RemoveDeadValues.cpp b/mlir/lib/Transforms/RemoveDeadValues.cpp
index 055256903a1522..1cc0096805616c 100644
--- a/mlir/lib/Transforms/RemoveDeadValues.cpp
+++ b/mlir/lib/Transforms/RemoveDeadValues.cpp
@@ -191,10 +191,10 @@ static void cleanSimpleOp(Operation *op, RunLivenessAnalysis &la) {
 ///   non-live across all callers),
 ///   (5) Dropping the uses of these return values from its callers, AND
 ///   (6) Erasing these return values
-/// iff it is not public.
+/// iff it is not public or declaration.
 static void cleanFuncOp(FunctionOpInterface funcOp, Operation *module,
                         RunLivenessAnalysis &la) {
-  if (funcOp.isPublic())
+  if (funcOp.isPublic() || funcOp.isDeclaration())
     return;
 
   // Get the list of unnecessary (non-live) arguments in `nonLiveArgs`.
diff --git a/mlir/test/Transforms/remove-dead-values.mlir b/mlir/test/Transforms/remove-dead-values.mlir
index 69426fdb620832..41027a6a6632eb 100644
--- a/mlir/test/Transforms/remove-dead-values.mlir
+++ b/mlir/test/Transforms/remove-dead-values.mlir
@@ -357,3 +357,8 @@ func.func @kernel(%arg0: memref<18xf32>) {
 // CHECK: gpu.launch blocks
 // CHECK: memref.store
 // CHECK-NEXT: gpu.terminator
+
+// -----
+
+// CHECK: func.func private @no_block_func_declaration() -> ()
+func.func private @no_block_func_declaration() -> ()



More information about the Mlir-commits mailing list