[Mlir-commits] [mlir] [mlir][LivenessAnalysis] Remove unnecessary addDependency on results (PR #179149)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Feb 1 15:22:18 PST 2026


https://github.com/neildhar created https://github.com/llvm/llvm-project/pull/179149

The framework already calls `addDependency` through `getLatticeElementFor` before `visitOperation` is invoked with the lattices. We don't need to call it again here.

>From c7c5162e75f54d8ffb870cb5cd4d9bfa05cfc685 Mon Sep 17 00:00:00 2001
From: Neil Dhar <neildhar at meta.com>
Date: Sun, 1 Feb 2026 15:19:17 -0800
Subject: [PATCH] [mlir][LivenessAnalysis] Remove unnecessary addDependency on
 results

The framework already calls `addDependency` through
`getLatticeElementFor` before `visitOperation` is invoked with the
lattices. We don't need to call it again here.
---
 .../Analysis/DataFlow/LivenessAnalysis.cpp    | 28 ++++++++-----------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/mlir/lib/Analysis/DataFlow/LivenessAnalysis.cpp b/mlir/lib/Analysis/DataFlow/LivenessAnalysis.cpp
index 4afc35d23fafa..7391f1d460c34 100644
--- a/mlir/lib/Analysis/DataFlow/LivenessAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/LivenessAnalysis.cpp
@@ -93,24 +93,20 @@ LivenessAnalysis::visitOperation(Operation *op, ArrayRef<Liveness *> operands,
   }
 
   // This marks values of type (3) liveness as "live".
-  bool foundLiveResult = false;
   for (const Liveness *r : results) {
-    if (r->isLive && !foundLiveResult) {
-      LDBG() << "[visitOperation] Found live result, "
-                "meeting all operands with result: "
-             << r;
-      // It is assumed that each operand is used to compute each result of an
-      // op. Thus, if at least one result is live, each operand is live.
-      for (Liveness *operand : operands) {
-        LDBG() << " [visitOperation] Meeting operand: " << operand
-               << " with result: " << r;
-        meet(operand, *r);
-      }
-      foundLiveResult = true;
+    if (!r->isLive)
+      continue;
+    LDBG() << "[visitOperation] Found live result, meeting all operands with "
+              "result: "
+           << r;
+    // It is assumed that each operand is used to compute each result of an op.
+    // Thus, if at least one result is live, each operand is live.
+    for (Liveness *operand : operands) {
+      LDBG() << " [visitOperation] Meeting operand: " << operand
+             << " with result: " << r;
+      meet(operand, *r);
     }
-    LDBG() << "[visitOperation] Adding dependency for result: " << r
-           << " after op: " << OpWithFlags(op, OpPrintingFlags().skipRegions());
-    addDependency(const_cast<Liveness *>(r), getProgramPointAfter(op));
+    break;
   }
   return success();
 }



More information about the Mlir-commits mailing list