-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[JIT] More ARM64 comparison instruction optimizations with Vector.Zero #64783
Merged
Merged
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
45611c1
Normalizing instructions with an implicit vector zero as the second o…
TIHan fcabd8f
Checking number of operands before looking at opernads
TIHan b46af4b
Remove assert
TIHan 9fe70b1
Check commutative flag
TIHan 1c58088
Fixed commutative check
TIHan ea9c1f8
Handling more HW intrinsics
TIHan e6dfa7e
Finishing up
TIHan f9f8dd2
Finishing up
TIHan 7d47671
Formatting
TIHan cdf3d60
numOperands = 1
TIHan a9c2989
Feedback
TIHan 9877252
Added HW_Flag_SupportsContainmentZero
TIHan d7e31d4
Added extra assert
TIHan 15f2b09
Merged with main
TIHan 1567e1c
Removing flag and simplifying codegen for containment with zeros
TIHan 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 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 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 |
---|---|---|
|
@@ -364,7 +364,45 @@ void CodeGen::genHWIntrinsic(GenTreeHWIntrinsic* node) | |
{ | ||
assert(!hasImmediateOperand); | ||
|
||
switch (intrin.numOperands) | ||
size_t numOperands = intrin.numOperands; | ||
|
||
// This handles optimizations for instructions that have | ||
// an implicit 'zero' vector of what would be the second operand. | ||
if ((numOperands == 2) && | ||
((intrin.op2->IsVectorZero() && intrin.op2->isContained()) || | ||
(intrin.op1->IsVectorZero() && intrin.op1->isContained() && | ||
HWIntrinsicInfo::IsCommutative(intrin.id)))) | ||
{ | ||
assert(HWIntrinsicInfo::SupportsContainment(intrin.id)); | ||
|
||
if (intrin.op1->IsVectorZero() && intrin.op1->isContained() && | ||
HWIntrinsicInfo::IsCommutative(intrin.id)) | ||
{ | ||
// The intrinsic is commutative, swap the registers. | ||
assert(op1Reg == REG_NA); | ||
op1Reg = op2Reg; | ||
op2Reg = REG_NA; | ||
} | ||
|
||
switch (ins) | ||
{ | ||
case INS_cmeq: | ||
case INS_cmge: | ||
case INS_cmgt: | ||
case INS_fcmeq: | ||
case INS_fcmge: | ||
case INS_fcmgt: | ||
{ | ||
numOperands -= 1; | ||
TIHan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
break; | ||
} | ||
|
||
default: | ||
unreached(); | ||
} | ||
} | ||
|
||
switch (numOperands) | ||
{ | ||
case 1: | ||
GetEmitter()->emitIns_R_R(ins, emitSize, targetReg, op1Reg, opt); | ||
|
@@ -499,29 +537,6 @@ void CodeGen::genHWIntrinsic(GenTreeHWIntrinsic* node) | |
GetEmitter()->emitIns_R_R_R(ins, emitSize, targetReg, op1Reg, op2Reg, opt); | ||
break; | ||
|
||
case NI_AdvSimd_CompareEqual: | ||
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. This part was removed in favor of the table driven approach as it was simpler to handle the instructions explicitly rather than the intrinsics. |
||
case NI_AdvSimd_Arm64_CompareEqual: | ||
case NI_AdvSimd_Arm64_CompareEqualScalar: | ||
if (intrin.op1->isContained()) | ||
{ | ||
assert(HWIntrinsicInfo::SupportsContainment(intrin.id)); | ||
assert(intrin.op1->IsVectorZero()); | ||
|
||
GetEmitter()->emitIns_R_R(ins, emitSize, targetReg, op2Reg, opt); | ||
} | ||
else if (intrin.op2->isContained()) | ||
{ | ||
assert(HWIntrinsicInfo::SupportsContainment(intrin.id)); | ||
assert(intrin.op2->IsVectorZero()); | ||
|
||
GetEmitter()->emitIns_R_R(ins, emitSize, targetReg, op1Reg, opt); | ||
} | ||
else | ||
{ | ||
GetEmitter()->emitIns_R_R_R(ins, emitSize, targetReg, op1Reg, op2Reg, opt); | ||
} | ||
break; | ||
|
||
case NI_AdvSimd_AbsoluteCompareLessThan: | ||
case NI_AdvSimd_AbsoluteCompareLessThanOrEqual: | ||
case NI_AdvSimd_CompareLessThan: | ||
|
This file contains 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.
I wonder if it's worth a small helper to cover these 5 instructions since they get grouped together a few times
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 agree, having the helper would be nice.
But this can be done in a follow up PR.
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.
FYI, this is the jit coding convention around subexpressions (including Boolean expressions)
https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/clr-jit-coding-conventions.md#11.1