[Mlir-commits] [mlir] [mlir][dataflow] Add visitBranchRegionArgument interface to SparseBackwardDataFlowAnalysis and apply it in LivenessAnalysis/RemoveDeadValues (PR #169816)

lonely eagle llvmlistbot at llvm.org
Sun Dec 21 01:15:59 PST 2025


================
@@ -609,12 +609,24 @@ void AbstractSparseBackwardDataFlowAnalysis::visitRegionSuccessors(
            *getLatticeElementFor(getProgramPointAfter(op), input));
       unaccounted.reset(operand.getOperandNumber());
     }
+
+    if (successor.isParent())
+      continue;
+    auto arguments = successor.getSuccessor()->getArguments();
+    for (BlockArgument argument : arguments) {
+      if (llvm::find(inputs, argument) == inputs.end()) {
+        regionArguments.push_back(argument);
+      }
+    }
   }
   // All operands not forwarded to regions are typically parameters of the
   // branch operation itself (for example the boolean for if/else).
   for (int index : unaccounted.set_bits()) {
     visitBranchOperand(op->getOpOperand(index));
   }
+  for (BlockArgument argument : regionArguments) {
+    visitBranchRegionArgument(argument);
----------------
linuxlonelyeagle wrote:

> > Assuming that's correct, should this function maybe be called visitNonControlFlowArguments, similar to the SparseForwardDataFlowAnalysis?
> 
> Yes. And more generally, this analysis should just use the `SparseForwardDataFlow` template, but dependencies in the codebase make it tricky.

I believe we still need to discuss this matter further. 
* I’ve looked into the code, and it seems the purpose of `visitNonControlFlowArguments` in `SparseForwardDataFlowAnalysis` is to visit the ControlFlowArguments in order to infer the results's lattices of the regionOp. You can see https://github.com/llvm/llvm-project/blob/3eee451e1829b21bac571f758896e7b44c500106/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp#L325.
Do we need to rename it?
* `IntegerRangeAnalysis` calls `visitNonControlFlowArguments`, which checks if the regionOp implements `LoopLikeOpInterface` and then analyzes the IV ranges. Perhaps we can also handle it using the logic we discussed.
https://github.com/llvm/llvm-project/blob/fc4661aa11a0e974f842e83346ff44609284a4ae/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp#L206

https://github.com/llvm/llvm-project/pull/169816


More information about the Mlir-commits mailing list