[Mlir-commits] [mlir] [mlir][vector] Restrict DropInnerMostUnitDimsTransferWrite (PR #96218)

Benjamin Maxwell llvmlistbot at llvm.org
Wed Jul 10 06:44:31 PDT 2024


MacDue wrote:

I'm not convinced that the transform you show in the description is invalid. 

```
func.func @negative_example(
    %arg0: memref<16x1xf32>,
    %arg1: vector<8x1xf32>,
    %idx_1: index,
    %idx_2: index) {
  vector.transfer_write %arg1, %arg0[%idx_1, %idx_2] {in_bounds = [true, true]} : vector<8x1xf32>, memref<16x1xf32>
  return
}
```
Looking at this there's no mask and both dims are marked as in_bounds. Therefore `%idx_2` _must_ be 0, as the in_bounds attribute "specifies for every vector dimension if the transfer is **guaranteed** to be within the source bounds". 

So the program is invalid (and I think it invokes UB) if `%idx_2` is not zero (as it breaks that guarantee).

If `%idx_2` was marked as out-of-bounds (mask or no mask), I believe knowing that the dimension is 1 then it means the write can probably be optimized-out. To avoid the out-bounds-write would mean masking out the entire unit dimension, which means the write would be a no-op.

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


More information about the Mlir-commits mailing list