[Mlir-commits] [mlir] a34d565 - [mlir][DeadCodeAnalysis] Fix predecessors when running DeadCodeAnalysis on callable (#179146)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Feb 2 07:33:18 PST 2026
Author: neildhar
Date: 2026-02-02T07:33:11-08:00
New Revision: a34d5653d52a82b8cfe90149ee8739d890a86b2d
URL: https://github.com/llvm/llvm-project/commit/a34d5653d52a82b8cfe90149ee8739d890a86b2d
DIFF: https://github.com/llvm/llvm-project/commit/a34d5653d52a82b8cfe90149ee8739d890a86b2d.diff
LOG: [mlir][DeadCodeAnalysis] Fix predecessors when running DeadCodeAnalysis on callable (#179146)
Added:
mlir/test/Analysis/DataFlow/test-dead-code-analysis-func.mlir
Modified:
mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
Removed:
################################################################################
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