-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[CIR] Upstream comparison ops for VectorType #140597
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
AmrDeveloper
merged 3 commits into
llvm:main
from
AmrDeveloper:cir_upstream_vec_cmp_ops
May 23, 2025
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 |
|---|---|---|
|
|
@@ -2105,4 +2105,33 @@ def VecExtractOp : CIR_Op<"vec.extract", [Pure, | |
| let hasFolder = 1; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // VecCmpOp | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def VecCmpOp : CIR_Op<"vec.cmp", [Pure, SameTypeOperands]> { | ||
|
|
||
| let summary = "Compare two vectors"; | ||
| let description = [{ | ||
| The `cir.vec.cmp` operation does an element-wise comparison of two vectors | ||
| of the same type. The result is a vector of the same size as the operands | ||
| whose element type is the signed integral type that is the same size as the | ||
| element type of the operands. The values in the result are 0 or -1. | ||
|
|
||
| ```mlir | ||
| %eq = cir.vec.cmp(eq, %vec_a, %vec_b) : !cir.vector<4 x !s32i>, !cir.vector<4 x !s32i> | ||
| %lt = cir.vec.cmp(lt, %vec_a, %vec_b) : !cir.vector<4 x !s32i>, !cir.vector<4 x !s32i> | ||
| ``` | ||
| }]; | ||
|
|
||
| let arguments = (ins Arg<CmpOpKind, "cmp kind">:$kind, CIR_VectorType:$lhs, | ||
| CIR_VectorType:$rhs); | ||
| let results = (outs CIR_VectorType:$result); | ||
|
|
||
| let assemblyFormat = [{ | ||
| `(` $kind `,` $lhs `,` $rhs `)` `:` qualified(type($lhs)) `,` | ||
| qualified(type($result)) attr-dict | ||
| }]; | ||
|
Member
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. Looks like we could get a folder here as well as follow up work at some point :) |
||
| } | ||
|
|
||
| #endif // CLANG_CIR_DIALECT_IR_CIROPS_TD | ||
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
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.
Is there a reason we can't just have
cir.cmpwork with vector types?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.
A new operation was created rather than reusing
cir.cmpbecause the result is a vector of a signed integral type, not a bool.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.
I guess that makes sense based on the C/C++ language handling, but I see that the classic codegen generates a vector of i1 and then sign-extends it to the size of the elements that were compared. and we lower to that same pattern when we go to the LLVM dialect.
This is fine for now, but I think we should consider using
cir.cmp + cir.cast(bool_to_int)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.
Right, but it does that extension within each lane (https://godbolt.org/z/3Ybez5cv5).
CmpOpresult isCIR_BoolTypewhich has no relation with the operands. This is different fromVecCmpOp, where the result matches the operands. If we were to makeCmpOpmore flexible, the operation would have to skip constraints and defer to a hand written verifier (and maybe more?) - this is also fine, but in these situations is just more common in MLIR to create a new op.What advantages do you think this might bring to CIR? It only seems to create more indirections when analyzing vector comparisons. IMO this is fine as a LLVM lowering details.