-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[CIR] Implement builtin extractf #170427
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
Open
badumbatish
wants to merge
6
commits into
llvm:main
Choose a base branch
from
badumbatish:cir_extract
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+327
−11
Open
[CIR] Implement builtin extractf #170427
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4ceae74
Implement extractf, tests are from clang/test/CodeGen/X86/avx512f-bui…
badumbatish 7de533b
Resolve PR reviews
badumbatish f1d16e8
Address PR comments except verifiers
badumbatish b50c2d7
Add verifier for select op
badumbatish a1130b3
Merge remote-tracking branch 'upstream' into cir_extract
badumbatish ced00b3
Add a valid test case where we validly select the whole vector from a…
badumbatish 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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -425,6 +425,27 @@ def CIR_ConstantOp : CIR_Op<"const", [ | |||||||||||
| return boolAttr.getValue(); | ||||||||||||
| llvm_unreachable("Expected a BoolAttr in ConstantOp"); | ||||||||||||
| } | ||||||||||||
| bool isAllOnesValue() { | ||||||||||||
|
Comment on lines
427
to
+428
Contributor
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.
Suggested change
|
||||||||||||
| // Check for -1 integers | ||||||||||||
| if (auto intAttr = getValueAttr<cir::IntAttr>()) | ||||||||||||
| return intAttr.getValue().isAllOnes(); | ||||||||||||
|
|
||||||||||||
| // Check for FP which are bitcasted from -1 integers | ||||||||||||
| if (auto fpAttr = getValueAttr<cir::FPAttr>()) | ||||||||||||
| return fpAttr.getValue().bitcastToAPInt().isAllOnes(); | ||||||||||||
|
|
||||||||||||
badumbatish marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
| // Check for constant vectors with splat values | ||||||||||||
| if (cir::VectorType v = mlir::dyn_cast<cir::VectorType>(getType())) | ||||||||||||
| if (auto vecAttr = getValueAttr<mlir::DenseElementsAttr>()) | ||||||||||||
| if (vecAttr.isSplat()) { | ||||||||||||
| auto splatAttr = vecAttr.getSplatValue<mlir::Attribute>(); | ||||||||||||
| if (auto splatInt = mlir::dyn_cast<cir::IntAttr>(splatAttr)) { | ||||||||||||
| return splatInt.getValue().isAllOnes(); | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| return false; | ||||||||||||
| } | ||||||||||||
| }]; | ||||||||||||
|
|
||||||||||||
| let hasFolder = 1; | ||||||||||||
|
|
@@ -1949,10 +1970,16 @@ def CIR_SelectOp : CIR_Op<"select", [ | |||||||||||
| let summary = "Yield one of two values based on a boolean value"; | ||||||||||||
| let description = [{ | ||||||||||||
| The `cir.select` operation takes three operands. The first operand | ||||||||||||
| `condition` is a boolean value of type `!cir.bool`. The second and the third | ||||||||||||
| operand can be of any CIR types, but their types must be the same. If the | ||||||||||||
| first operand is `true`, the operation yields its second operand. Otherwise, | ||||||||||||
| the operation yields its third operand. | ||||||||||||
| `condition` is either a boolean value of type `!cir.bool` or a boolean | ||||||||||||
| vector of type `!cir.bool`. The second and the third operand can be of | ||||||||||||
| any CIR types, but their types must be the same. If the first operand | ||||||||||||
| is `true`, the operation yields its second operand. Otherwise, the | ||||||||||||
| operation yields its third operand. | ||||||||||||
|
|
||||||||||||
| In the case where the first operand is a boolean vector, then the second | ||||||||||||
| and third operand needs to also be of some vectors of the same type to | ||||||||||||
| each other and that the number of elements of all three operands needs to | ||||||||||||
| be the same as well. | ||||||||||||
|
|
||||||||||||
| Example: | ||||||||||||
|
|
||||||||||||
|
|
@@ -1964,8 +1991,12 @@ def CIR_SelectOp : CIR_Op<"select", [ | |||||||||||
| ``` | ||||||||||||
| }]; | ||||||||||||
|
|
||||||||||||
| let arguments = (ins CIR_BoolType:$condition, CIR_AnyType:$true_value, | ||||||||||||
| CIR_AnyType:$false_value); | ||||||||||||
| let arguments = (ins | ||||||||||||
| CIR_ScalarOrVectorOf<CIR_BoolType>:$condition, | ||||||||||||
| CIR_AnyType:$true_value, | ||||||||||||
| CIR_AnyType:$false_value | ||||||||||||
| ); | ||||||||||||
|
|
||||||||||||
badumbatish marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
| let results = (outs CIR_AnyType:$result); | ||||||||||||
|
|
||||||||||||
| let assemblyFormat = [{ | ||||||||||||
|
|
@@ -1978,6 +2009,7 @@ def CIR_SelectOp : CIR_Op<"select", [ | |||||||||||
| }]; | ||||||||||||
|
|
||||||||||||
| let hasFolder = 1; | ||||||||||||
| let hasVerifier = 1; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| //===----------------------------------------------------------------------===// | ||||||||||||
|
|
||||||||||||
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2330,6 +2330,28 @@ OpFoldResult cir::SelectOp::fold(FoldAdaptor adaptor) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LogicalResult cir::SelectOp::verify() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
2332
to
+2333
Contributor
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.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // INFO: No need to check if trueTy == falseTy here, it's verified by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // the AllTypesMatch trait already. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // We can go straight into getting the vector type. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto condVecTy = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mlir::dyn_cast<cir::VectorType>(this->getCondition().getType()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto trueVecTy = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mlir::dyn_cast<cir::VectorType>(this->getTrueValue().getType()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto falseVecTy = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mlir::dyn_cast<cir::VectorType>(this->getFalseValue().getType()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (condVecTy && (!trueVecTy || !falseVecTy)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // INFO: No need to check for size of vector here, it's verified by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // the AllTypesMatch trait already | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return emitOpError() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| << "second and third operand must both be of the same " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "vector type when" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| " the conditional operand is of vector boolean type"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return mlir::success(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
2332
to
+2354
Contributor
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.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| //===----------------------------------------------------------------------===// | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ShiftOp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.