-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][Vector] Verify that masked ops implement MaskableOpInterface #108123
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6124,7 +6124,9 @@ LogicalResult MaskOp::verify() { | |
Block &block = getMaskRegion().getBlocks().front(); | ||
if (block.getOperations().empty()) | ||
return emitOpError("expects a terminator within the mask region"); | ||
if (block.getOperations().size() > 2) | ||
|
||
unsigned numMaskRegionOps = block.getOperations().size(); | ||
if (numMaskRegionOps > 2) | ||
return emitOpError("expects only one operation to mask"); | ||
|
||
// Terminator checks. | ||
|
@@ -6136,11 +6138,14 @@ LogicalResult MaskOp::verify() { | |
return emitOpError( | ||
"expects number of results to match mask region yielded values"); | ||
|
||
auto maskableOp = dyn_cast<MaskableOpInterface>(block.front()); | ||
// Empty vector.mask. Nothing else to check. | ||
if (!maskableOp) | ||
if (numMaskRegionOps == 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be comparing against 0? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a terminator/ |
||
return success(); | ||
|
||
auto maskableOp = dyn_cast<MaskableOpInterface>(block.front()); | ||
if (!maskableOp) | ||
return emitOpError("expects a MaskableOpInterface within the mask region"); | ||
|
||
// Result checks. | ||
if (maskableOp->getNumResults() != getNumResults()) | ||
return emitOpError("expects number of results to match maskable operation " | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Seems like
MaskOp::getMaskableOp()
is redundantly testing for this condition unnecessarily, and theMaskOpRewritePattern
is then usingcast_or_null
wherecast
could be used?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.
MaskOp can be empty so that's why
getMaskableOp()
is checking for something similar to returnnullptr
. That's also the reason to usecast_or_null
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.
Oh right!
The code is confusing, and not the most efficient:
if (block->getOperations().size() < 2)
(size()
on a linked list isO(N)
).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.
Yep, that's why I introduced
numMaskRegionOps
instead of callingsize()
again. However, a valid vector mask would always have 2 ops at most so I thought it would be acceptable. I could implement similar logic withblock.getOperations().empty()
+ compareblock.getOperations().begin()
andblock.getOperations().end()
but I think it would make it more confusing... WDYT?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.
LG