Fix for out of range rotate amount during lower - #131909
Draft
dhartglassMSFT wants to merge 7 commits into
Draft
Conversation
|
Azure Pipelines: Successfully started running 5 pipeline(s). 11 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 the JIT’s handling of rotate counts to avoid out-of-range rotate amounts reaching lowering, including enabling import of variable rotate amounts for primitive intrinsics, and adds a regression test for the arm64 lowering assert scenario.
Changes:
- Mask rotate counts explicitly in morphing so rotate nodes always have counts normalized to
[0, bitsize-1]. - Strip redundant
AND(count, mask)for rotates during lowering on targets that implicitly mask rotate counts. - Refactor RotateLeft/RotateRight intrinsic importing into a shared helper and allow non-constant rotate amounts (with explicit masking), plus add a regression test.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/jit/morph.cpp | Adds explicit masking of rotate counts when recognizing/morphing rotation patterns. |
| src/coreclr/jit/lower.cpp | Adds TryRemoveShiftRotateMask and uses it to strip redundant rotate-count masks prior to lowering rotates on relevant targets. |
| src/coreclr/jit/lower.h | Declares TryRemoveShiftRotateMask helper used by lowering. |
| src/coreclr/jit/importercalls.cpp | Introduces impRotateHelper and uses it for RotateLeft/RotateRight, including masked variable rotate counts. |
| src/coreclr/jit/compiler.h | Adds the impRotateHelper declaration. |
| src/tests/JIT/Regression/JitBlue/Runtime_129298/Runtime_129298.cs | Adds regression test ensuring JIT compiles the dead rotate block without asserting. |
| src/tests/JIT/Regression/Regression_ro_2.csproj | Includes the new regression test source file in the project. |
Comment on lines
+12537
to
+12539
| // Explicitly mask the rotate amount to the range [0, bitsize-1]. Otherwise, a later | ||
| // tranform can stick an out of range constant here and trip up lowering. If the | ||
| // target's rotate or shift instructions mask their operand implicitly, those targets |
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/coreclr/jit/lower.cpp:8875
- The
LowerShiftdoc comment still refers specifically to xarch, but this helper is used for multiple targets (see theTARGET_XARCH || TARGET_ARM64 || TARGET_LOONGARCH64 || TARGET_RISCV64call sites). Updating the comment would avoid misleading future readers about why the mask removal is safe here.
// Notes:
// Remove unnecessary shift count masking, xarch shift instructions
// mask the shift count to 5 bits (or 6 bits for 64 bit operations).
//
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.
Assert during arm64 lower that rotate amount on a rotate node (ROR, ROL) was an out of range integer
Change to instead add explicit masking onto rotate nodes in the jit (
AND op (CNS_INT 63)for ex.), and to strip the mask during lower like is done already for shiftsAlso change importercalls to allow non-constant rotate amounts onto the node. Gives a couple nice diffs where we can generate ROR now instead of a call.
There's a single bad diff caused by CSE deduplicating the explicit masks, which ends up defeating the lowering mask-stripping logic. This bug exists already for SHIFTS (not rotates) so this is an extant issue, I'll try and open a bug.
fixes #129298