[Mlir-commits] [mlir] [MLIR][RemoveDeadValues] Fix affine.for induction variable incorrectly removed (PR #172612)

Francisco Geiman Thiesen llvmlistbot at llvm.org
Wed Dec 17 09:57:26 PST 2025


================
@@ -327,6 +328,32 @@ RunLivenessAnalysis::RunLivenessAnalysis(Operation *op) {
   solver.load<LivenessAnalysis>(symbolTable);
   LDBG() << "Initializing and running solver";
   (void)solver.initializeAndRun(op);
+
+  // Mark block arguments of RegionBranchOpInterface ops that are NOT successor
+  // inputs as live. These include induction variables (IVs) like those in
+  // affine.for or scf.for. The fix in visitBranchOperand() only handles this
+  // when non-forwarded operands exist, but ops like affine.for with constant
+  // bounds have no non-forwarded operands, so visitBranchOperand() is never
+  // called. We must handle this case here during initialization.
+  op->walk([&](RegionBranchOpInterface regionBranchOp) {
----------------
FranciscoThiesen wrote:

Yes we can, thanks for the suggestion:

In the last commit:
- Merged the two separate op->walk() calls into a single traversal
- The walk now visits all operations once, and for each:
    a. If it's a RegionBranchOpInterface, mark non-successor-input args live
    b. Create dead states for values without liveness info (unreachable code handling)

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


More information about the Mlir-commits mailing list