-
Notifications
You must be signed in to change notification settings - Fork 14.2k
[MLIR] Avoid vector.extract_strided_slice
when not needed
#115941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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 `@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. Signed-off-by: Alan Li <[email protected]>
@llvm/pr-subscribers-mlir-vector @llvm/pr-subscribers-mlir Author: lialan (lialan) ChangesIn This fixes the lit test case Full diff: https://github.com/llvm/llvm-project/pull/115941.diff 1 Files Affected:
diff --git a/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp b/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp
index 7578aadee23a6e..6fd6ccc04e8045 100644
--- a/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp
+++ b/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp
@@ -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});
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a lit test with this? I thought that this was meant to fix a lit test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lialan told me that it is fixing the post CI failures. E.g., https://buildkite.com/llvm-project/github-pull-requests/builds/118845
Please add the link to the PR description which makes is clearer.
@hanhanW Thanks Hanhan, updated the PR description to include more information about this. |
Tried to build a lit test for it, but it actually totally overlaps with the existing failing test. So I specifically mentioned such case int the PR description. |
Do we understand why this fails there but not for the post-merge bots? The test is passing here at head for example: https://lab.llvm.org/buildbot/#/builders/138/builds/6300/steps/6/logs/stdio I'd really like a test I could reproduce locally for this! |
Ah, there is a race when I clicked the merge button and you left a comment.. Any preference how to proceed here? |
assert(frontOffset + subvecSize <= vectorType.getNumElements() && | ||
"subvector out of bounds"); | ||
|
||
// do not need extraction if the subvector size is the same as the source |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Use proper sentences in code comments: https://llvm.org/docs/CodingStandards.html#commenting
In
staticallyExtractSubvector
, When the extracting slice is the same as source vector, do not need to emitvector.extract_strided_slice
.This fixes the lit test case
@vector_store_i4
inmlir\test\Dialect\Vector\vector-emulate-narrow-type.mlir
, where converting fromvector<8xi4>
tovector<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.