Repository navigation
JIT: preserve negation of division by the signed minimum - #135459
Merged
Merged
Conversation
PR description draft: <!-- --> Do not distribute negation into a signed division's constant divisor when that divisor is the minimum value for the operation's type. Its negation is not representable, so the rewrite changes the result from -1 to 1 when the dividend is also the signed minimum. Add a single-file regression covering int, long, and nint, including the minimum and surrounding boundary values. Fixes dotnet#133517 Co-authored-by: Copilot <[email protected]> Copilot-Session: ae8155d6-f240-4542-a1da-c721ba933c91
|
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.
🟢 Approval recommended
The targeted guard correctly preserves division semantics, and the regression test covers all affected types.
0 open findings
What changed in this PR
Fixes incorrect JIT negation distribution when dividing by a signed minimum value.
Changes:
- Prevents the unsafe rewrite for
int,long, andnintminimum divisors. - Adds focused regression coverage across representative dividends.
| File | Description |
|---|---|
src/coreclr/jit/morph.cpp |
Excludes signed minimum divisors from negation distribution. |
src/tests/JIT/Regression_ro_2/Runtime_133517.cs |
Verifies correct results for affected integral types. |
🧠 Review effort: Balanced
EgorBo
marked this pull request as ready for review
October 9, 2026 01:37
Member
Author
|
PTAL @dotnet/jit-contrib |
JulieLeeMSFT
approved these changes
Oct 9, 2026
JulieLeeMSFT
left a comment
Member
There was a problem hiding this comment.
LGTM.
z = -(x / MinValue)
Old morph: NEG(DIV(x, MinValue))
│
▼ (incorrectly distributes negation)
DIV(x, -MinValue) // -MinValue overflows, equals MinValue again!
New morph: NEG(DIV(x, MinValue))
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.
Do not distribute negation into a signed division's constant divisor when that divisor is the minimum value for the operation's type. Its negation is not representable, so the rewrite changes the result from -1 to 1 when the dividend is also the signed minimum.
Fixes #133517
Almost no diffs