MLIR Buffer Deallocation and memref store

Hi guys,

I’m using the BufferDeallocation passes but I’m front of a behavior that I don’t expect, to resume I have this mlir code:

func @main() -> memref<1xmemref<1xi64>> {
  %0 = memref.alloc() : memref<1xi64>
  %1 = memref.alloc() : memref<1xmemref<1xi64>>
  %c0 = constant 0 : index
  memref.store %0, %1[%c0] : memref<1xmemref<1xi64>>
  return %1 : memref<1xmemref<1xi64>>
}

So I wonder to have 0 dealloc or at least a clone operation on %0 before storing. But what I have running the buffer deallocation passes (mlir-opt -buffer-deallocation) is:

module  {
  func @main() -> memref<1xmemref<1xi64>> {
    %0 = memref.alloc() : memref<1xi64>
    %1 = memref.alloc() : memref<1xmemref<1xi64>>
    %c0 = constant 0 : index
    memref.store %0, %1[%c0] : memref<1xmemref<1xi64>>
    memref.dealloc %0 : memref<1xi64>
    return %1 : memref<1xmemref<1xi64>>
  }
}

So my question is this is an expected behavior of the buffer deallocation?

I had to read your example twice before I noticed that you are using nested memrefs. I don’t actually know what the semantics of storing a memref to a memref is.

In any case, nested memrefs are not supported by the deallocation pass. They came into existence after that pass was developed.