[Mlir-commits] [mlir] [mlir][Bufferization]Support to_tensor / to_buffer in One-Shot Bufferize analysis (PR #170261)

Matthias Springer llvmlistbot at llvm.org
Tue Dec 2 23:21:28 PST 2025


matthias-springer wrote:

Here is another one: This should bufferize without a copy, but the `memref.alloc` is considered "not writable", causing out-of-place bufferization. It looks like that's because you are merging memrefs into the tensor alias sets. The infrastructure was not designed for that.

```
$ cat a.mlir 
func.func @foo() {
  %0 = memref.alloc() : memref<10xf32>
  %1 = bufferization.to_tensor %0 restrict writable : memref<10xf32> to tensor<10xf32>
  %c0 = arith.constant 0 : index
  %cst2 = arith.constant 6.0 : f32
  %3 = tensor.insert %cst2 into %1[%c0] : tensor<10xf32>
  return
}

$ build/bin/mlir-opt a.mlir -one-shot-bufferize="test-analysis-only print-conflicts"
module {
  func.func @foo() {
    %alloc = memref.alloc() {"W_0[NOT-WRITABLE: result 0]"} : memref<10xf32>
    %0 = bufferization.to_tensor %alloc restrict writable : memref<10xf32> to tensor<10xf32>
    %c0 = arith.constant 0 : index
    %cst = arith.constant 6.000000e+00 : f32
    %inserted = tensor.insert %cst into %0[%c0] {__inplace_operands_attr__ = ["none", "false", "none"]} : tensor<10xf32>
    return
  }
}
```


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


More information about the Mlir-commits mailing list