Skip to content

Commit 24a8092

Browse files
authored
[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 <[email protected]>
1 parent 36fa8bd commit 24a8092

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ static Value staticallyExtractSubvector(OpBuilder &rewriter, Location loc,
150150
assert((vectorType.getRank() == 1 && extractType.getRank() == 1) &&
151151
"expected 1-D source and destination types");
152152
(void)vectorType;
153+
assert(frontOffset + subvecSize <= vectorType.getNumElements() &&
154+
"subvector out of bounds");
155+
156+
// do not need extraction if the subvector size is the same as the source
157+
if (vectorType.getNumElements() == subvecSize)
158+
return source;
159+
153160
auto offsets = rewriter.getI64ArrayAttr({frontOffset});
154161
auto sizes = rewriter.getI64ArrayAttr({subvecSize});
155162
auto strides = rewriter.getI64ArrayAttr({1});

0 commit comments

Comments
 (0)