Mark additional commutative xarch and arm64 intrinsics and instructions#130984
Open
tannergooding wants to merge 2 commits into
Open
Mark additional commutative xarch and arm64 intrinsics and instructions#130984tannergooding wants to merge 2 commits into
tannergooding wants to merge 2 commits into
Conversation
AVX2 and AVX512 MultiplyAddAdjacent used the same instructions as the X86Base variant (pmaddubsw/pmaddwd) but were missing HW_Flag_MaybeCommutative, so the pmaddwd form lost the operand-swap-for-containment the SSE path gets. Add the flag and the matching isCommutativeHWIntrinsic cases; pmaddubsw stays non-commutative since its operands are asymmetric (unsigned x signed). Several SSE4.1/SSSE3 integer instructions that are commutative were also not marked INS_Flags_IsAvxCommutative, unlike their SSE2 siblings. Mark pcmpeqq, pmuldq, pmulld, pmaxsb/sd/ud/uw, pminsb/sd/ud/uw, and pmulhrsw so the emitter can swap op1/op2 to enable the shorter 2-byte VEX prefix when op2 is an extended register. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 5 pipeline(s). 10 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates xarch commutativity metadata in the JIT so operand swapping can be applied more consistently for containment / encoding decisions.
Changes:
- Marks
AVX2andAVX512MultiplyAddAdjacentasHW_Flag_MaybeCommutativeinhwintrinsiclistxarch.h. - Extends
GenTree::isCommutativeHWIntrinsicto treatNI_AVX2_MultiplyAddAdjacentandNI_AVX512_MultiplyAddAdjacentas conditionally commutative (non-shortbase types). - Marks additional xarch SIMD instructions as
INS_Flags_IsAvxCommutativeininstrsxarch.h.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/jit/instrsxarch.h | Adds INS_Flags_IsAvxCommutative to more VEX/EVEX instructions. |
| src/coreclr/jit/hwintrinsiclistxarch.h | Marks AVX2/AVX512 MultiplyAddAdjacent as maybe-commutative. |
| src/coreclr/jit/gentree.cpp | Adds commutativity switch-cases for AVX2/AVX512 MultiplyAddAdjacent. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 1
The double and scalar fabd forms compute |a-b|, which is commutative and NaN/signed-zero safe, matching the float32 AdvSimd.AbsoluteDifference sibling that already carries the flag. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Open
3 tasks
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.
Fixes commutativity-metadata gaps found while auditing the xarch and arm64 hwintrinsic/instruction tables.
xarch
AVX2andAVX512MultiplyAddAdjacentuse the same instructions as theX86Basevariant (pmaddubsw/pmaddwd) but were missingHW_Flag_MaybeCommutative.isCommutativeHWIntrinsiconly special-casedNI_X86Base_MultiplyAddAdjacent, so thepmaddwdform of the AVX2/AVX512 intrinsics lost the operand-swap-for-containment opportunity the SSE path already gets. This adds the flag to both rows and the matching switch cases. Thepmaddubswform (base typeshort) correctly stays non-commutative since its operands are asymmetric (unsigned x signed); only thepmaddwdform (base typeint) becomes commutative, matching the existing!varTypeIsShort(...)condition.Several
SSE4.1/SSSE3integer instructions that are commutative were not markedINS_Flags_IsAvxCommutative, unlike theirSSE2siblings (pmaxsw,pminsw,pmuludq, etc.). This markspcmpeqq,pmuldq,pmulld,pmaxsb,pmaxsd,pmaxud,pmaxuw,pminsb,pminsd,pminud,pminuw, andpmulhrsw. These are allSSE38/SSE3A-encoded, so the emitter always forces a 3-byte VEX prefix and theemitIns_SIMD_R_R_Roperand swap can't drop to the 2-byte form -- i.e. it's a no-op for code size here. Kept anyway for consistency with theSSE2siblings: the flag correctly describes the instruction and avoids these rows looking like they're missing it. If the swap heuristic is ever tightened to skipSSE38/SSE3A, that's a single localized change.arm64
AdvSimd_Arm64.AbsoluteDifference(fabd,double) andAbsoluteDifferenceScalar(fabd,float/doublescalar) were missingHW_Flag_Commutative, even though the float32AdvSimd.AbsoluteDifferencesibling -- the samefabdinstruction -- already carries it.fabdcomputes|a-b|, which is commutative and NaN/signed-zero safe. This enables constant-to-op2 reordering in morph and CSE canonicalization, matching the sibling.The SVE commutativity gap (no
Sve/Sve2op carriesHW_Flag_Commutative) is left out of scope -- those forms are predicated/RMW/embedded-mask and need separate investigation rather than a metadata one-liner.Validation
clr+libs -rc checkedbaseline build succeeded; JIT rebuilt with 0 warnings / 0 errors. The arm64 altjit (clrjit_universal_arm64_x64) also builds clean, compiling the arm64 table change.jitformat.py -r . -o windows -a x64reports no formatting changes.Note
This PR was authored by GitHub Copilot.