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

Federico Bruzzone llvmlistbot at llvm.org
Fri Oct 2 00:19:56 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;
----------------
FedericoBruzzone wrote:

Could you clarify why this check is needed?

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


More information about the Mlir-commits mailing list