[Mlir-commits] [mlir] [mlir][bufferization] handle exit aliases in buffer-loop-hoisting (PR #226951)
Matthias Springer
llvmlistbot at llvm.org
Sun Oct 11 17:41:54 PDT 2026
================
@@ -66,6 +69,49 @@ static bool isSequentialLoop(Operation *op) {
return !op->hasTrait<OpTrait::HasParallelRegion>() && isLoop(op);
}
+/// Returns true if an allocation 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(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()))
+ return false;
+
+ // Check all aliases, including loop results: memory effects alone do not rule
+ // out capture or uses that depend on allocation identity or lifetime.
+ for (Value alias : aliases) {
+ if (!isa<BaseMemRefType>(alias.getType()))
+ return false;
+ for (OpOperand &use : alias.getUses()) {
+ Operation *user = use.getOwner();
+ if (user->getParentOp() != loop && user->getBlock() != loop->getBlock())
+ return false;
+ if (auto load = dyn_cast<memref::LoadOp>(user)) {
+ if (load.getInvariant())
+ return false;
----------------
matthias-springer wrote:
Why does an `invariant` load disqualify hoisting? Can you add a comment?
https://github.com/llvm/llvm-project/pull/226951
More information about the Mlir-commits
mailing list