[Mlir-commits] [mlir] [mlir][dataflow] Cleanup liveness analysis (NFC) (PR #172874)

lonely eagle llvmlistbot at llvm.org
Thu Dec 18 08:15:57 PST 2025


https://github.com/linuxlonelyeagle created https://github.com/llvm/llvm-project/pull/172874

In the implementation of visitBranchOperand within the LivenessAnalysis, there is logic to set the operand as live if its associated region has memory-effecting operations or if the return value of the branchOp is live. In this scenario, the subsequent call to the visitOperation function is redundant. Similarly, for cases where the operand should be set as dead, we also do not need to process it by calling visitOperation.

>From a65553b54603b83b319e5b0e0ca540df3c5ccf55 Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Thu, 18 Dec 2025 15:58:13 +0000
Subject: [PATCH] cleanup liveness analysis.

---
 .../Analysis/DataFlow/LivenessAnalysis.cpp    | 28 -------------------
 1 file changed, 28 deletions(-)

diff --git a/mlir/lib/Analysis/DataFlow/LivenessAnalysis.cpp b/mlir/lib/Analysis/DataFlow/LivenessAnalysis.cpp
index 20be50c8e8a5b..71bf3cc5156d3 100644
--- a/mlir/lib/Analysis/DataFlow/LivenessAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/LivenessAnalysis.cpp
@@ -254,34 +254,6 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
       propagateIfChanged(argumentLiveness, argumentLiveness->markLive());
     }
   }
-
-  // Now that we have checked for memory-effecting ops in the blocks of concern,
-  // we will simply visit the op with this non-forwarded operand to potentially
-  // mark it "live" due to type (1.a/3) liveness.
-  SmallVector<Liveness *, 4> operandLiveness;
-  operandLiveness.push_back(getLatticeElement(operand.get()));
-  for (BlockArgument argument : argumentNotOperand)
-    operandLiveness.push_back(getLatticeElement(argument));
-  SmallVector<const Liveness *, 4> resultsLiveness;
-  for (const Value result : op->getResults())
-    resultsLiveness.push_back(getLatticeElement(result));
-  LDBG() << "Visiting operation for non-forwarded branch operand: "
-         << OpWithFlags(op, OpPrintingFlags().skipRegions());
-  (void)visitOperation(op, operandLiveness, resultsLiveness);
-
-  // We also visit the parent op with the parent's results and this operand if
-  // `op` is a `RegionBranchTerminatorOpInterface` because its non-forwarded
-  // operand depends on not only its memory effects/results but also on those of
-  // its parent's.
-  if (!isa<RegionBranchTerminatorOpInterface>(op))
-    return;
-  Operation *parentOp = op->getParentOp();
-  SmallVector<const Liveness *, 4> parentResultsLiveness;
-  for (const Value parentResult : parentOp->getResults())
-    parentResultsLiveness.push_back(getLatticeElement(parentResult));
-  LDBG() << "Visiting parent operation for non-forwarded branch operand: "
-         << *parentOp;
-  (void)visitOperation(parentOp, operandLiveness, parentResultsLiveness);
 }
 
 void LivenessAnalysis::visitCallOperand(OpOperand &operand) {



More information about the Mlir-commits mailing list