Help ensure we get the smallest encoding for commutative instructions#128521
Open
tannergooding wants to merge 6 commits into
Open
Help ensure we get the smallest encoding for commutative instructions#128521tannergooding wants to merge 6 commits into
tannergooding wants to merge 6 commits into
Conversation
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new “commutative” instruction flag for xarch SIMD/AVX instructions and uses it in the xarch emitter to opportunistically swap op1/op2 for commutative 3-operand SIMD instructions, improving the chances of using a smaller (2-byte) VEX prefix when only one source register is “extended”.
Changes:
- Add
INS_Flags_IsCommutativetoinsFlagsand mark a set of commutative SIMD instructions with it. - Add
emitter::IsAvxCommutativeand use it inemitIns_SIMD_R_R_Rto swap operands whenop2is extended butop1is not. - Wire the new helper into the emitter’s xarch interface.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/coreclr/jit/instrsxarch.h | Marks specific VEX/EVEX SIMD instructions as commutative via INS_Flags_IsCommutative. |
| src/coreclr/jit/instr.h | Introduces the new INS_Flags_IsCommutative bit in the xarch insFlags enum. |
| src/coreclr/jit/emitxarch.h | Declares the new emitter::IsAvxCommutative helper. |
| src/coreclr/jit/emitxarch.cpp | Implements IsAvxCommutative and adds operand-swapping logic in emitIns_SIMD_R_R_R. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The VEX 2-byte encoding allows
REX.Rto be on or off while it requires thatREX.Bbe off. This means thatop1can encode[XMM0, XMM15]whileop2can only encode `[XMM0, XMM7]. Thus, when we have a commutative instruction we want to check for this scenario and swap the operands. If both are not "extended" then we'll get the 2-byte encoding regardless, while if both are extended we'll require the 3-byte encoding.This doesn't handle some of the comparison cases that also qualify but which require swapping the comparison that is being done.