[Mlir-commits] [mlir] [mlir][dataflow] Fix LivenessAnalysis/RemoveDeadValues handling of loop induction variables (PR #161117)

Mehdi Amini llvmlistbot at llvm.org
Mon Oct 20 08:02:40 PDT 2025


================
@@ -165,6 +165,28 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
           blocks.push_back(&block);
       }
     }
+
+    // In the block of the successor block argument of RegionBranchOpInterface,
+    // there may be arguments of RegionBranchOpInterface, such as the IV of
+    // scf.forOp. Explicitly set this argument to live.
+    auto regionBranchOp = cast<RegionBranchOpInterface>(op);
+    for (size_t i = 0, e = op->getNumRegions(); i < e; ++i) {
+      SmallVector<RegionSuccessor> successors;
+      regionBranchOp.getSuccessorRegions(op->getRegion(i), successors);
+      for (RegionSuccessor successor : successors) {
+        if (successor.isParent())
+          continue;
+        auto arguments = successor.getSuccessor()->getArguments();
+        ValueRange regionInputs = successor.getSuccessorInputs();
+        for (auto argument : arguments) {
+          if (llvm::find(regionInputs, argument) == regionInputs.end()) {
+            (void)getLatticeElement(argument)->markLive();
+            LDBG() << "Marking RegionBranchOp's success argument live: "
+                   << argument;
+          }
+        }
+      }
+    }
----------------
joker-eph wrote:

Isn't this something where we should instead propagate the liveness of the result backward to the loop carried value instead of marking it unconditionally live?

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


More information about the Mlir-commits mailing list