[Mlir-commits] [mlir] [mlir][scf] Do not coalesce when an inner loop reads an outer iter_arg (PR #216853)

Federico Bruzzone llvmlistbot at llvm.org
Sat Sep 5 01:07:30 PDT 2026


================
@@ -1006,6 +1006,24 @@ LogicalResult mlir::coalesceLoops(RewriterBase &rewriter,
       }
     }
   }
+
+  // Bail out if an iteration argument of an enclosing loop is read anywhere
+  // other than as the init operand of the loop nested in it. Coalescing maps
+  // the iteration arguments of every loop in the band onto the ones of the
+  // outermost loop, which turns such a read into a read of the value carried by
+  // the coalesced loop. That value is updated on every iteration, whereas the
+  // one being read is fixed for a whole run of the inner loop. This covers both
+  // a read inside the inner loop's region and, in an imperfect nest, one from
+  // an operation sitting between the two loops.
----------------
FedericoBruzzone wrote:

This comment is very verbose. I think we should document this behavior, but with few words. Additionally, if I understand correctly (please correct me if I'm wrong), this is a conservative approach... if so, I'll write it explicitly. 

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


More information about the Mlir-commits mailing list