[mlir][vector] Add pattern to break down vector.bitcast
authorQuinn Dawkins <quinn@nod-labs.com>
Thu, 6 Apr 2023 20:45:59 +0000 (16:45 -0400)
committerQuinn Dawkins <quinn@nod-labs.com>
Wed, 26 Apr 2023 00:18:02 +0000 (20:18 -0400)
commit650f04feda9039e170de513dab261c672fa847cd
tree7b71fa380ec9b1519d338c65f1c41b9df13dbebf
parentfc28560fd675a93f06d73628b469fbe3c6850282
[mlir][vector] Add pattern to break down vector.bitcast

The pattern added here is intended as a last resort for targets like
SPIR-V where there are vector size restrictions and we need to be able
to break down large vector types. Vectorizing loads/stores for small
bitwidths (e.g. i8) relies on bitcasting to a larger element type and
patterns to bubble bitcast ops to where they can cancel.
This fails for cases such as
```
%1 = arith.trunci %0 : vector<2x32xi32> to vector<2x32xi8>
vector.transfer_write %1, %destination[%c0, %c0] {in_bounds = [true, true]} : vector<2x32xi8>, memref<2x32xi8>
```
where the `arith.trunci` op essentially does the job of one of the
bitcasts, leading to a bitcast that need to be further broken down
```
vector.bitcast %0 : vector<16xi8> to vector<4xi32>
```

Differential Revision: https://reviews.llvm.org/D149065
mlir/include/mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h
mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp
mlir/test/Dialect/Vector/vector-break-down-bitcast.mlir [new file with mode: 0644]
mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp