-
Notifications
You must be signed in to change notification settings - Fork 5.5k
arm64: Optimize ARM64 compare mask ExtractMostSignificantBits consumers #129688
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
jonathandavies-arm
wants to merge
5
commits into
dotnet:main
Choose a base branch
from
jonathandavies-arm:upstream/sve/intrinsic-ExtractMostSignificantBits
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.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e37c384
arm64: Optimize ARM64 compare mask ExtractMostSignificantBits consumers
jonathandavies-arm ab8c027
JIT: Track zero/all-bits SIMD masks for EMSB rewrites
jonathandavies-arm f6c2d69
Fix formatting
jonathandavies-arm 9753a90
Address compare mask PR feedback
jonathandavies-arm 85bed58
Fix formatting
jonathandavies-arm 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 |
|---|---|---|
|
|
@@ -78,6 +78,147 @@ static Range GetRange(Compiler* comp, GenTree* tree, BasicBlock* block, ASSERT_V | |
| return Limit(Limit::keUnknown); | ||
| } | ||
|
|
||
| #if defined(FEATURE_HW_INTRINSICS) && defined(TARGET_ARM64) | ||
| //---------------------------------------------------------------------------------------------- | ||
| // AllComponentsEitherZeroOrAllBitsSet: Check if a SIMD VN has per-element boolean values. | ||
| // | ||
| // Arguments: | ||
| // comp - The compiler instance | ||
| // vn - The value number | ||
| // baseType - The expected SIMD element base type | ||
| // | ||
| // Return Value: | ||
| // True if every SIMD element is known to be either all-bits-set or zero. | ||
| // | ||
| static bool AllComponentsEitherZeroOrAllBitsSet(Compiler* comp, ValueNum vn, var_types baseType) | ||
| { | ||
| if (vn == ValueNumStore::NoVN) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| vn = comp->vnStore->VNNormalValue(vn); | ||
|
|
||
| if (comp->vnStore->IsVNConstant(vn)) | ||
| { | ||
| switch (comp->vnStore->TypeOfVN(vn)) | ||
| { | ||
| case TYP_SIMD8: | ||
| { | ||
| simd8_t val = comp->vnStore->GetConstantSimd8(vn); | ||
| return val.IsAllBitsSet() || val.IsZero(); | ||
| } | ||
|
|
||
| case TYP_SIMD16: | ||
| { | ||
| simd16_t val = comp->vnStore->GetConstantSimd16(vn); | ||
| return val.IsAllBitsSet() || val.IsZero(); | ||
| } | ||
|
|
||
| default: | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| VNFuncApp funcApp; | ||
| NamedIntrinsic intrinsicId; | ||
| unsigned simdSize; | ||
| var_types intrinsicSimdBaseType; | ||
|
|
||
| if (!comp->vnStore->IsVNHWIntrinsicFunc(vn, &funcApp, &intrinsicId, &simdSize, &intrinsicSimdBaseType)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| if ((simdSize != 8) && (simdSize != 16)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| bool isScalar = false; | ||
| genTreeOps oper = GenTreeHWIntrinsic::GetOperForHWIntrinsicId(intrinsicId, baseType, &isScalar); | ||
|
|
||
| if (isScalar) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| switch (oper) | ||
| { | ||
| case GT_EQ: | ||
| case GT_NE: | ||
| case GT_GT: | ||
| case GT_GE: | ||
| case GT_LE: | ||
| case GT_LT: | ||
| { | ||
| // The comparison intrinsic may have used a wider unsigned base type to produce the | ||
| // per-element mask, e.g. a TYP_BYTE compare can be implemented as TYP_UBYTE. | ||
| return varTypeIsIntegral(baseType) && (genTypeSize(baseType) <= genTypeSize(intrinsicSimdBaseType)); | ||
| } | ||
|
|
||
| case GT_NOT: | ||
| { | ||
| return AllComponentsEitherZeroOrAllBitsSet(comp, funcApp.GetArg(0), baseType); | ||
| } | ||
|
|
||
| case GT_OR: | ||
| case GT_AND: | ||
| case GT_XOR: | ||
| case GT_AND_NOT: | ||
| { | ||
| return AllComponentsEitherZeroOrAllBitsSet(comp, funcApp.GetArg(0), baseType) && | ||
| AllComponentsEitherZeroOrAllBitsSet(comp, funcApp.GetArg(1), baseType); | ||
| } | ||
|
|
||
| default: | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| //---------------------------------------------------------------------------------------------- | ||
| // optAssertionProp_HWIntrinsic: Propagate VN-derived facts to hwintrinsic tree flags. | ||
| // | ||
| // Arguments: | ||
| // comp - The compiler instance | ||
| // tree - The hwintrinsic node | ||
|
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. lack of |
||
| // | ||
| static void optAssertionProp_HWIntrinsic(Compiler* comp, GenTreeHWIntrinsic* tree) | ||
| { | ||
| NamedIntrinsic intrinsic = tree->GetHWIntrinsicId(); | ||
|
|
||
| if ((intrinsic != NI_Vector64_ExtractMostSignificantBits) && (intrinsic != NI_Vector128_ExtractMostSignificantBits)) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| assert(tree->GetOperandCount() == 1); | ||
|
|
||
| GenTree* op1 = tree->Op(1); | ||
|
|
||
| if (op1->OperIsHWIntrinsic() && !Compiler::IsHWIntrinsicCmpMask(op1->AsHWIntrinsic()->GetHWIntrinsicId())) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| ValueNum op1VN = comp->vnStore->VNConservativeNormalValue(op1->gtVNPair); | ||
|
|
||
| auto vnVisitor = [comp, tree](ValueNum vn) -> ValueNumStore::VNVisit { | ||
| return AllComponentsEitherZeroOrAllBitsSet(comp, vn, tree->GetSimdBaseType()) ? ValueNumStore::VNVisit::Continue | ||
| : ValueNumStore::VNVisit::Abort; | ||
| }; | ||
|
|
||
| if (comp->vnStore->VNVisitReachingVNs(op1VN, vnVisitor) == ValueNumStore::VNVisit::Continue) | ||
| { | ||
| tree->gtFlags |= GTF_HW_ZERO_OR_ALL_BITS_SET; | ||
|
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. You need to fix GenTree::Compare - it should take this flag into account and return false if the rest is the same. |
||
| } | ||
| } | ||
| #endif // FEATURE_HW_INTRINSICS && TARGET_ARM64 | ||
|
|
||
| //------------------------------------------------------------------------ | ||
| // SymbolicToRealValue: Convert a symbolic value to a 64-bit signed integer. | ||
| // | ||
|
|
@@ -5867,6 +6008,12 @@ GenTree* Compiler::optAssertionProp(ASSERT_VALARG_TP assertions, GenTree* tree, | |
| case GT_CALL: | ||
| return optAssertionProp_Call(assertions, tree->AsCall(), stmt); | ||
|
|
||
| #if defined(FEATURE_HW_INTRINSICS) && defined(TARGET_ARM64) | ||
| case GT_HWINTRINSIC: | ||
| optAssertionProp_HWIntrinsic(this, tree->AsHWIntrinsic()); | ||
| return nullptr; | ||
| #endif // FEATURE_HW_INTRINSICS && TARGET_ARM64 | ||
|
|
||
| case GT_EQ: | ||
| case GT_NE: | ||
| case GT_LT: | ||
|
|
||
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.
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.
I'd leave a comment for <=, the original impl had it.