Skip to content

JIT: sign-extend folded 32-bit RotateLeft/RotateRight constants - #135833

Merged
EgorBo merged 2 commits into
dotnet:mainfrom
EgorBo:fix/jit-135814-rotate-signext
Oct 15, 2026
Merged

EgorBo merged 2 commits into
dotnet:mainfrom
EgorBo:fix/jit-135814-rotate-signext

Conversation

@EgorBo

@EgorBo EgorBo commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

impRotateHelper folds 32-bit rotates of constants into a uint32_t and passed it to gtNewIconNode, which zero-extended it on 64-bit hosts. TYP_INT constants must be sign-extended, so a result with bit 31 set (e.g. int.RotateLeft(1, 31)) was treated as +2^31 and comparisons against it were folded incorrectly. Cast the result to int32_t.

Fixes #135814
Fixes #129099

No diffs

impRotateHelper folds 32-bit rotates of constants into a uint32_t and passed it to gtNewIconNode,
which zero-extended it on 64-bit hosts. TYP_INT constants must be sign-extended, so a result with
bit 31 set (e.g. int.RotateLeft(1, 31)) was treated as +2^31 and comparisons against it were folded
incorrectly. Cast the result to int32_t.

Fixes dotnet#135814

Fixes dotnet#129099

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6ec7c151-8b7f-4bf9-8b1a-8c601a2965ec
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Oct 15, 2026
@azure-pipelines

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The unsigned test omits the multiple-use pattern needed to cover the reported Checked-build assertion.

1 open finding
What changed in this PR

Fixes JIT constant folding for 32-bit rotations whose results have the sign bit set.

Changes:

  • Sign-extends folded results before creating integer constant nodes.
  • Adds signed-comparison and unsigned-rotation regression tests.

Builds and tests were not run.

File Description
src/​tests/​JIT/​Regression_ro_2/​Runtime_135814.cs Adds rotation regression coverage.
src/​coreclr/​jit/​importercalls.cpp Corrects folded constant representation.

🧠 Review effort: Balanced

@EgorBo
EgorBo requested a review from a team October 15, 2026 13:09
@EgorBo

EgorBo commented Oct 15, 2026

Copy link
Copy Markdown
Member Author

PTAL @dotnet/jit-contrib, trivial change, no diffs

@EgorBo
EgorBo merged commit 6b1cd4b into dotnet:main Oct 15, 2026
134 of 136 checks passed
@EgorBo
EgorBo deleted the fix/jit-135814-rotate-signext branch October 15, 2026 18:11
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

3 participants