Fix JIT range analysis Multiply for ranges spanning negative values#124128
Open
Fix JIT range analysis Multiply for ranges spanning negative values#124128
Conversation
…ll endpoint products and add regression test for #124082 Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix bad result with multiplication and casts in JIT
Fix JIT range analysis Multiply for ranges spanning negative values
Feb 7, 2026
This was referenced Feb 7, 2026
Open
Member
|
@jakobbotsch @dotnet/jit-contrib PTAL fix for fuzzlyn failures. Previous logic was incorrectly multiplying |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes CoreCLR JIT range analysis for multiplication when operand ranges span negative values, preventing incorrect bounds that can lead to wrong codegen (notably around casts).
Changes:
- Update
RangeOps::Multiplyto use standard interval-arithmetic multiplication (min/max of all four endpoint products) with overflow checking. - Add a JIT regression test reproducing #124082 (Fuzzlyn-reduced).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/coreclr/jit/rangecheck.h | Correct range multiplication by considering all endpoint product combinations and rejecting overflow cases. |
| src/tests/JIT/Regression/JitBlue/Runtime_124082/Runtime_124082.cs | Adds regression coverage for the cast/multiply miscompile reported in #124082. |
kg
approved these changes
Feb 7, 2026
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.
Description
RangeOps::MultiplyusedApplyRangeOpwhich independently multipliedlo*loandhi*hi. This is wrong when ranges span negative values — e.g.[-100..100] * [0..10]produced[0..1000]instead of[-1000..1000], causing incorrect codegen for expressions involving multiplication with casts.The fix computes
min/maxacross all four endpoint products (r1lo*r2lo,r1lo*r2hi,r1hi*r2lo,r1hi*r2hi), which is the standard interval arithmetic approach for multiplication.src/coreclr/jit/rangecheck.h: ReplaceMultiply— require constant ranges, check all four products for overflow, compute correct min/max boundssrc/tests/JIT/Regression/JitBlue/Runtime_124082/: Add Fuzzlyn regression test from the issueOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.