-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[mlir][Vector] Add vector.extract(vector.shuffle) folder #115105
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1705,6 +1705,46 @@ static Value foldExtractFromBroadcast(ExtractOp extractOp) { | |
| return extractOp.getResult(); | ||
| } | ||
|
|
||
| /// Fold extractOp coming from ShuffleOp. | ||
| /// | ||
| /// Example: | ||
| /// | ||
| /// %shuffle = vector.shuffle %a, %b [0, 8, 7, 15] | ||
| /// : vector<8xf32>, vector<8xf32> | ||
| /// %extract = vector.extract %shuffle[3] : f32 from vector<4xf32> | ||
| /// -> | ||
| /// %extract = vector.extract %b[7] : f32 from vector<4xf32> | ||
| /// | ||
| static Value foldExtractFromShuffle(ExtractOp extractOp) { | ||
| // TODO: Canonicalization for dynamic position not implemented yet. | ||
| if (extractOp.hasDynamicPosition()) | ||
| return Value(); | ||
|
||
|
|
||
| auto shuffleOp = extractOp.getVector().getDefiningOp<ShuffleOp>(); | ||
| if (!shuffleOp) | ||
| return Value(); | ||
|
|
||
| // TODO: 0-D or multi-dimensional vectors not supported yet. | ||
| if (shuffleOp.getResultVectorType().getRank() != 1) | ||
| return Value(); | ||
|
|
||
| int64_t inputVecSize = shuffleOp.getV1().getType().getShape()[0]; | ||
| auto shuffleMask = shuffleOp.getMask(); | ||
| int64_t extractIdx = extractOp.getStaticPosition()[0]; | ||
| int64_t shuffleIdx = shuffleMask[extractIdx]; | ||
|
|
||
| // Find the shuffled vector to extract from based on the shuffle index. | ||
| if (shuffleIdx < inputVecSize) { | ||
| extractOp.setOperand(0, shuffleOp.getV1()); | ||
| extractOp.setStaticPosition({shuffleIdx}); | ||
| } else { | ||
| extractOp.setOperand(0, shuffleOp.getV2()); | ||
| extractOp.setStaticPosition({shuffleIdx - inputVecSize}); | ||
| } | ||
|
|
||
| return extractOp.getResult(); | ||
| } | ||
|
|
||
| // Fold extractOp with source coming from ShapeCast op. | ||
| static Value foldExtractFromShapeCast(ExtractOp extractOp) { | ||
| // TODO: Canonicalization for dynamic position not implemented yet. | ||
|
|
@@ -1953,6 +1993,8 @@ OpFoldResult ExtractOp::fold(FoldAdaptor) { | |
| return res; | ||
| if (auto res = foldExtractFromBroadcast(*this)) | ||
| return res; | ||
| if (auto res = foldExtractFromShuffle(*this)) | ||
| return res; | ||
| if (auto res = foldExtractFromShapeCast(*this)) | ||
| return res; | ||
| if (auto val = foldExtractFromExtractStrided(*this)) | ||
|
|
||
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.