This is an archive of the discontinued LLVM Phabricator instance.

[mlir][vector] Convert extract_strided_slice to extract & insert chain
ClosedPublic

Authored by antiagainst on Nov 4 2022, 3:58 PM.

Details

Summary

This is useful for breaking down extract_strided_slice and potentially
cancel with other extract / insert ops before or after.

Diff Detail

Event Timeline

antiagainst created this revision.Nov 4 2022, 3:58 PM
Herald added a project: Restricted Project. · View Herald Transcript
antiagainst requested review of this revision.Nov 4 2022, 3:58 PM

And control and fix tests

ThomasRaoux added inline comments.Nov 6 2022, 10:06 PM
mlir/lib/Dialect/Vector/Transforms/VectorInsertExtractStridedSliceRewritePatterns.cpp
238

Shouldn't this be equivalent to Convert1DExtractStridedSliceIntoShuffle?

antiagainst marked an inline comment as done.Nov 7 2022, 10:18 AM
antiagainst added inline comments.
mlir/lib/Dialect/Vector/Transforms/VectorInsertExtractStridedSliceRewritePatterns.cpp
238

Not really. The purpose of having such patterns is trying to break down and clean up IRs of the following:

%v0 = vector.insert %scalar0 into %init[0] : f16 into vector<8xf16>
%v1 = vector.insert %scalar1 into %v0[1] : f16 into vector<8xf16>
...
%v7 = vector.insert %scalar7 into %v0[7] : f16 into vector<8xf16>

%e0 = vector.extract_strided_slice %v7 {offsets = [0], sizes = [4], strides = [1]} : vector<8xf16> to vector<4xf16>
%e1 = vector.extract_strided_slice %v7 {offsets = [4], sizes = [4], strides = [1]} : vector<8xf16> to vector<4xf16>

With this new pattern and various vector.extract/vector.insert canonicalization patterns we can completely avoid the vector<8xf16>; just buiding up %e0 and %e1 as vector<4xf16> from scalars. This is required for SPPIR-V to work given we cannot accept vector<8xf16> there.

The existing pattern that converts vector.extract_strided_slice into vector.shuffle, OTOH, still retains vector<8xf16> and the vector.insert chain building up it. So it won't work there.

ThomasRaoux accepted this revision.Nov 9 2022, 4:16 PM
This revision is now accepted and ready to land.Nov 9 2022, 4:16 PM
This revision was landed with ongoing or failed builds.Nov 9 2022, 4:42 PM
This revision was automatically updated to reflect the committed changes.
antiagainst marked an inline comment as done.