[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:25 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: None (neildhar)
<details>
<summary>Changes</summary>
`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.
---
Full diff: https://github.com/llvm/llvm-project/pull/179146.diff
2 Files Affected:
- (modified) mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp (+6)
- (added) mlir/test/Analysis/DataFlow/test-dead-code-analysis-func.mlir (+12)
``````````diff
diff --git a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
index 3ce0f94e0c6da..a71dfd3a42958 100644
--- a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
@@ -149,6 +149,12 @@ 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 (auto c = dyn_cast<CallableOpInterface>(top)) {
+ auto *state = getOrCreate<PredecessorState>(getProgramPointAfter(c));
+ propagateIfChanged(state, state->setHasUnknownPredecessors());
+ }
+
// 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
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/179146
More information about the Mlir-commits
mailing list