[MLIR] Avoid vector.extract_strided_slice when not needed (#115941)

In `staticallyExtractSubvector`, When the extracting slice is the same
as source vector, do not need to emit `vector.extract_strided_slice`.

This fixes the lit test case `@vector_store_i4` in
`mlir\test\Dialect\Vector\vector-emulate-narrow-type.mlir`, where
converting from `vector<8xi4>` to `vector<4xi8>` does not need slice
extraction.

The issue was introduced in #113411 and #115070, CI failure link:
https://buildkite.com/llvm-project/github-pull-requests/builds/118845

This PR does not include a lit test case because it is a fix and the
above mentioned `@vector_store_i4` test actually tests the mechanism.

Signed-off-by: Alan Li <me@alanli.org>
This commit is contained in:
lialan
2024-11-12 16:58:58 -05:00
committed by GitHub
parent 36fa8bdfa0
commit 24a8092be7

View File

@@ -150,6 +150,13 @@ static Value staticallyExtractSubvector(OpBuilder &rewriter, Location loc,
assert((vectorType.getRank() == 1 && extractType.getRank() == 1) &&
"expected 1-D source and destination types");
(void)vectorType;
assert(frontOffset + subvecSize <= vectorType.getNumElements() &&
"subvector out of bounds");
// do not need extraction if the subvector size is the same as the source
if (vectorType.getNumElements() == subvecSize)
return source;
auto offsets = rewriter.getI64ArrayAttr({frontOffset});
auto sizes = rewriter.getI64ArrayAttr({subvecSize});
auto strides = rewriter.getI64ArrayAttr({1});