[Mlir-commits] [mlir] [mlir][bufferization] handle exit aliases in buffer-loop-hoisting (PR #226951)

Matteo Di Iorio llvmlistbot at llvm.org
Fri Oct 2 00:58:48 PDT 2026


================
@@ -66,6 +69,55 @@ static bool isSequentialLoop(Operation *op) {
   return !op->hasTrait<OpTrait::HasParallelRegion>() && isLoop(op);
 }
 
+/// Returns true if an allocation in the before region can be reused across
+/// iterations when its aliases have a common dominator outside the while loop.
+/// `aliases` must contain the complete forward alias set of the allocation.
+static bool
+canHoistFromWhile(memref::AllocOp alloc, scf::WhileOp loop,
+                  const BufferViewFlowAnalysis::ValueSetT &aliases) {
+  // Further hoisting across an enclosing loop with unmodeled parallel
+  // execution could share the allocation across iterations.
+  if (!isa<FunctionOpInterface>(loop->getParentOp()) ||
+      !loop->getParentOp()->hasTrait<OpTrait::IsIsolatedFromAbove>())
+    return false;
+
+  // The single-block before region executes on entry, even if the condition
+  // is initially false. The after region may be skipped.
+  if (alloc->getBlock() != loop.getBeforeBody())
+    return false;
----------------
splicer3 wrote:

It was meant to keep the fallback limited to allocations that execute whenever the while is entered, but after checking the caller again I think it's redundant: if an allocation and its aliases stay in `after`, the existing dominator-based path handles it before reaching this helper, and if an alias is forwarded to `before`, the use check below already rejects `scf.yield`, including forwarding through casts or subviews.

I'll remove this check along the `alloc` parameter.

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


More information about the Mlir-commits mailing list