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

Federico Bruzzone llvmlistbot at llvm.org
Sun Oct 4 16:19:23 PDT 2026


================
@@ -371,14 +423,16 @@ struct BufferAllocationLoopHoistingState : BufferAllocationHoistingStateBase {
     return dependencyBlock ? dependencyBlock : nullptr;
   }
 
-  /// Returns true if the given operation represents a loop with sequential
-  /// execution semantics and one of the aliases caused the
-  /// `aliasDominatorBlock` to be "above" the block of the given loop operation.
-  /// If this is the case, it indicates that the allocation is passed via a back
-  /// edge.
+  /// Returns true if the allocation can be moved across the given loop.
   bool isLegalPlacement(Operation *op) {
-    return isSequentialLoop(op) &&
-           !dominators->dominates(aliasDominatorBlock, op->getBlock());
+    if (!isSequentialLoop(op))
+      return false;
+    if (!dominators->dominates(aliasDominatorBlock, op->getBlock()))
+      return true;
+    auto loop = dyn_cast<scf::WhileOp>(op);
+    if (!loop || !allocValue.getDefiningOp<memref::AllocOp>())
----------------
FedericoBruzzone wrote:

Thanks for the explanation. Could you put the `memref.realloc` reasoning in a comment here?

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


More information about the Mlir-commits mailing list