This is an archive of the discontinued LLVM Phabricator instance.

[mlir][vector] Add pattern to break down vector.bitcast
ClosedPublic

Authored by qedawkins on Apr 24 2023, 7:48 AM.

Details

Summary

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>

Diff Detail

Event Timeline

qedawkins created this revision.Apr 24 2023, 7:48 AM
Herald added a project: Restricted Project. · View Herald Transcript
qedawkins requested review of this revision.Apr 24 2023, 7:48 AM
kuhar added a comment.Apr 24 2023, 8:13 AM

LGTM. You may want to wait for a review from Lei before submitting.

mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp
856

nit: Location loc and Type elemType

870

nit: I'd think a regular for loop would work fine here

kuhar accepted this revision.Apr 24 2023, 8:13 AM
This revision is now accepted and ready to land.Apr 24 2023, 8:13 AM

Address comments

antiagainst accepted this revision.Apr 25 2023, 2:43 PM

LGTM! Thanks for adding this!

This revision was automatically updated to reflect the committed changes.

LGTM! Wondering if it would make more sense to move these SPIR-V specific patterns to some kind of SPIR-V legalization group of patterns. Are there cases where this can be useful in general?