[Mlir-commits] [mlir] [mlir][DeadCodeAnalysis] Fix predecessors when running DeadCodeAnalysis on callable (PR #179146)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Feb 1 14:40:47 PST 2026
https://github.com/neildhar updated https://github.com/llvm/llvm-project/pull/179146
>From 85fe9ca0a8cf4ead9d0bc31a6838786490ba1759 Mon Sep 17 00:00:00 2001
From: Neil Dhar <neildhar at meta.com>
Date: Sun, 1 Feb 2026 14:21:50 -0800
Subject: [PATCH] Fix predecessors when running DeadCodeAnalysis on callable
`initializeSymbolCallables` only identifies potentially escaping
functions inside a `SymbolTable` operation. If the top level operation
is itself a callable, we should always treat it as escaping because we
are not analysing its potential users.
---
mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp | 8 ++++++++
.../DataFlow/test-dead-code-analysis-func.mlir | 12 ++++++++++++
2 files changed, 20 insertions(+)
create mode 100644 mlir/test/Analysis/DataFlow/test-dead-code-analysis-func.mlir
diff --git a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
index 3ce0f94e0c6da..936b0c678f20c 100644
--- a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
@@ -149,6 +149,14 @@ LogicalResult DeadCodeAnalysis::initialize(Operation *top) {
<< OpWithFlags(top, OpPrintingFlags().skipRegions());
}
+ // If the top level op is a callable, we cannot identify all of its callers.
+ if (isa<CallableOpInterface>(top)) {
+ auto *state = getOrCreate<PredecessorState>(getProgramPointAfter(top));
+ propagateIfChanged(state, state->setHasUnknownPredecessors());
+ LDBG() << "[init] Marked callable root as having unknown predecessors: "
+ << OpWithFlags(top, OpPrintingFlags().skipRegions());
+ }
+
// Mark as overdefined the predecessors of symbol callables with potentially
// unknown predecessors.
initializeSymbolCallables(top);
diff --git a/mlir/test/Analysis/DataFlow/test-dead-code-analysis-func.mlir b/mlir/test/Analysis/DataFlow/test-dead-code-analysis-func.mlir
new file mode 100644
index 0000000000000..b9c1e72e5be56
--- /dev/null
+++ b/mlir/test/Analysis/DataFlow/test-dead-code-analysis-func.mlir
@@ -0,0 +1,12 @@
+// RUN: mlir-opt --pass-pipeline="builtin.module(func.func(test-dead-code-analysis))" 2>&1 %s | FileCheck %s
+
+// Test that when dead code analysis is run on a single function, we correctly
+// identify that we do not know all of the predecessors.
+// CHECK: foo:
+// CHECK-NEXT: region #0
+// CHECK-NEXT: ^bb0 = live
+// CHECK-NEXT: op_preds: predecessors: (none)
+func.func @foo(%arg0: i32) -> i32
+ attributes {tag = "foo"} {
+ return {a} %arg0 : i32
+}
More information about the Mlir-commits
mailing list