[Mlir-commits] [mlir] [mlir][bufferization] Trace write-side subset provenance (PR #228995)
Matthias Springer
llvmlistbot at llvm.org
Thu Oct 8 21:30:27 PDT 2026
https://github.com/matthias-springer commented:
This PR seems to introduce a correctness bug. Reproducer from a coding agent:
```mlir
func.func @loop(%t: tensor<4xf32> {bufferization.writable = true}) -> f32 {
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%c4 = arith.constant 4 : index
%zero = arith.constant 0.0 : f32
%value = arith.constant 100.0 : f32
%result = scf.for %i = %c1 to %c4 step %c1 iter_args(%sum = %zero) -> f32 {
%prev = arith.subi %i, %c1 : index
%lhs = tensor.extract_slice %t[%i][1][1] : tensor<4xf32> to tensor<1xf32>
%rhs = tensor.extract_slice %t[%prev][1][1] : tensor<4xf32> to tensor<1xf32>
%written = linalg.fill ins(%value : f32) outs(%lhs : tensor<1xf32>) -> tensor<1xf32>
%new = tensor.extract %written[%c0] : tensor<1xf32>
%old = tensor.extract %rhs[%c0] : tensor<1xf32>
%pair = arith.addf %new, %old : f32
%next = arith.addf %sum, %pair : f32
scf.yield %next : f32
}
return %result : f32
}
func.func @main() {
%t = arith.constant dense<[1.0, 2.0, 3.0, 4.0]> : tensor<4xf32>
%r = func.call @loop(%t) : (tensor<4xf32>) -> f32
vector.print %r : f32
return
}
```
The coding agent also found a case that previously bufferized in-place, but not triggers additional copies:
```mlir
func.func @nested(%t: tensor<8xf32> {bufferization.writable = true}, %s: tensor<4xf32>) -> (tensor<8xf32>, tensor<2xf32>) {
%written = tensor.insert_slice %s into %t[0][4][1] : tensor<4xf32> into tensor<8xf32>
%outer = tensor.extract_slice %t[4][4][1] : tensor<8xf32> to tensor<4xf32>
%inner = tensor.extract_slice %outer[0][2][1] : tensor<4xf32> to tensor<2xf32>
return %written, %inner : tensor<8xf32>, tensor<2xf32>
}
```
Can you also comment on the compilation time overhead of this PR?
https://github.com/llvm/llvm-project/pull/228995
More information about the Mlir-commits
mailing list