[release/9.0] JIT ARM64: Don't emit mov for zero case in jump tables for shift intrinsics#107487
Merged
jeffschwMSFT merged 11 commits intorelease/9.0from Sep 11, 2024
Merged
Conversation
This reverts commit cd2656f.
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
|
@tannergooding PTAL, thanks! |
jeffschwMSFT
approved these changes
Sep 9, 2024
Member
jeffschwMSFT
left a comment
There was a problem hiding this comment.
approved. please get a code review. we can merge when ready
tannergooding
approved these changes
Sep 9, 2024
Contributor
|
@jeffschwMSFT I got approval from Tanner; could you please merge this when you have a moment? Thanks! |
Member
|
@amanasifkhalid, you can merge after tests pass. |
Contributor
|
@JulieLeeMSFT I'm afraid I don't have permission to merge into |
Contributor
|
@JulieLeeMSFT could you please merge this when you get the chance? Thanks! |
Contributor
cc @carlossanlop in case you're free |
This was referenced Sep 11, 2024
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Backport of #107322 to release/9.0
/cc @amanasifkhalid
Customer Impact
ARM64 has numerous shift intrinsics that encode the shift amount directly into the instruction. For right-shift intrinsics, we cannot directly encode a shift amount of zero, so another instruction must be used. Because shifting by zero is a no-op on its own, the JIT's emitter had a case to detect this pattern, and emit a
mov reg, reginstruction instead (the details as to why we couldn't skip emitting an instruction altogether aren't wholly relevant here). This worked for intrinsics likeAdvSimd.ShiftRightLogical, but for shift intrinsics with other side effects likeAdvSimd.ShiftLeftLogicalWideningLower, this would drop the side effects when shifting by zero. Our fix is to remove this special case from the emitter, such that if we are shifting by zero, we simply emit the intrinsic to ensure its side effects are preserved (the emitter will already assert if we try to encode a zero shift amount into aShiftRight*intrinsic).The importer already transforms uses of
ShiftRight*intrinsics with zero shift amounts into fallback implementations, but we weren't covering code patterns likeVector128<byte> >> 8, where the JIT masks the shift amount by the size of the base type such that it becomes zero. Thus, we've also updated the importer to convert such patterns to use a fallback implementation, too.This issue was discovered by Fuzzlyn, one of our test generation tools, and was tracked in #107173.
Regression
This seems to have been introduced during the .NET 9 dev cycle while fixing a different bug.
Testing
My PR includes regression tests to cover various intrinsic patterns that were explicitly fixed. This PR also passed our current suite of HW intrinsic tests, which exercise every
AdvSimd.Shift*intrinsic (as well as the<<and>>operators) with various inputs.Risk
Low. This fix changes codegen for a small subset of
AdvSimdintrinsics when shifting by zero, as well as the>>operator when shifting by multiples of the base type's size. I imagine neither of these patterns is all that common in our users' code.