Issue 101708
Summary [mlir][tensor] `InsertSliceOfTransferWriteOpFolder` does not check if write fully-overwrites destination
Labels good first issue, mlir, mlir:tensor
Assignees
Reporter MacDue
    Take this example:

```mlir
func.func @insert_slice_of_transfer_write(%arg0: tensor<1000x1000xf32>, %arg1: vector<5x6xf32>, %arg2: index, %arg3: tensor<100x100xf32>) -> tensor<1000x1000xf32> {
  %c0 = arith.constant 0 : index
  %0 = vector.transfer_write %arg1, %arg3[%c0, %c0] {in_bounds = [true, true]} : vector<5x6xf32>, tensor<100x100xf32>
  %inserted_slice = tensor.insert_slice %0 into %arg0[3, %arg2] [100, 100] [1, 1] : tensor<100x100xf32> into tensor<1000x1000xf32>
  return %inserted_slice : tensor<1000x1000xf32>
}
```

It becomes:
```mlir
func.func @insert_slice_of_transfer_write(%arg0: tensor<1000x1000xf32>, %arg1: vector<5x6xf32>, %arg2: index, %arg3: tensor<100x100xf32>) -> tensor<1000x1000xf32> {
  %c3 = arith.constant 3 : index
  %0 = vector.transfer_write %arg1, %arg0[%c3, %arg2] {in_bounds = [true, true]} : vector<5x6xf32>, tensor<1000x1000xf32>
  return %0 : tensor<1000x1000xf32>
}
```

The `transfer_write` only writes to `5x6` of the `100x100` elements in `%arg3`, but the `insert_slice` slice is eliminated (which may lead to incorrect results). The rewrite should be updated to check if the `transfer_write` overwrites all elements of the `insert_slice` (and only apply in those cases). This is easy for fixed-size tensors but may need something more complex (like value bounds analysis) for dynamic cases.

See: https://godbolt.org/z/sP9Ybz78a
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to