Add binary VN funcs to TryGetRangeFromAssertions#123233
Merged
EgorBo merged 5 commits intodotnet:mainfrom Jan 23, 2026
Merged
Conversation
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib |
This was referenced Jan 16, 2026
EgorBo
commented
Jan 20, 2026
jakobbotsch
reviewed
Jan 20, 2026
df7af53 to
7117893
Compare
74bbb1c to
c468b04
Compare
Member
Author
|
@jakobbotsch PTAL again, I still have a few ideas for a refactoring, but those should be zero diffs and will be in a separate PR. Now I am slowly moving towards repeating what SSA-based GetRange does, but only with VNs Some 50-100k improvements are expected - diffs - although, there are regressions from previously semi-legal transformations based on half-defined ranges (e.g. [10..unknown]) PS: I think I also spot a few potential bugs when we could perform a multiplication on top of keBinOpArray or add two keBinOpArrays PS2: I recommend disabling the whitespaces on the review view. |
3 tasks
Member
Author
|
ping @jakobbotsch |
jakobbotsch
approved these changes
Jan 23, 2026
EgorBo
added a commit
that referenced
this pull request
Feb 8, 2026
…124128) ## Description `RangeOps::Multiply` used `ApplyRangeOp` which independently multiplied `lo*lo` and `hi*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`/`max` across all four endpoint products (`r1lo*r2lo`, `r1lo*r2hi`, `r1hi*r2lo`, `r1hi*r2hi`), which is the standard interval arithmetic approach for multiplication. ```cpp int lo = min(min(r1lo * r2lo, r1lo * r2hi), min(r1hi * r2lo, r1hi * r2hi)); int hi = max(max(r1lo * r2lo, r1lo * r2hi), max(r1hi * r2lo, r1hi * r2hi)); ``` - `src/coreclr/jit/rangecheck.h`: Replace `Multiply` — require constant ranges, check all four products for overflow, compute correct min/max bounds - `src/tests/JIT/Regression/JitBlue/Runtime_124082/`: Add Fuzzlyn regression test from the issue <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>JIT: Bad result with multiplication and casts</issue_title> > <issue_description>```csharp > // Generated by Fuzzlyn v3.3 on 2026-02-05 22:00:13 > // Run on X64 Windows > // Seed: 3325744140221827777-vectort,vector128,vector256,x86aes,x86avx,x86avx2,x86avx512bw,x86avx512bwvl,x86avx512cd,x86avx512cdvl,x86avx512dq,x86avx512dqvl,x86avx512f,x86avx512fvl,x86avx512fx64,x86bmi1,x86bmi1x64,x86bmi2,x86bmi2x64,x86fma,x86lzcnt,x86lzcntx64,x86pclmulqdq,x86popcnt,x86popcntx64,x86sse,x86ssex64,x86sse2,x86sse2x64,x86sse3,x86sse41,x86sse41x64,x86sse42,x86sse42x64,x86ssse3,x86x86base > // Reduced from 64.4 KiB to 0.3 KiB in 00:01:42 > // Debug: Outputs -1 > // Release: Outputs 4294967295 > public class Program > { > public static sbyte s_4 = 1; > public static byte[][] s_12 = new byte[][] > { > new byte[] > { > 1 > } > }; > public static void Main() > { > byte[] vr9 = s_12[0]; > long vr10 = (ushort)s_4 * (sbyte)(-s_4); > System.Console.WriteLine(vr10); > } > } > ``` > > Bisected to #123233, cc @EgorBo </issue_description> > > <agent_instructions>Fix the #124082 bug. Replace Multiply impl with the following code: > > ```cpp > static Range Multiply(const Range& r1, const Range& r2) > { > if (!r1.IsConstantRange() || !r2.IsConstantRange()) > { > return Limit(Limit::keUnknown); > } > > int r1lo = r1.LowerLimit().GetConstant(); > int r1hi = r1.UpperLimit().GetConstant(); > int r2lo = r2.LowerLimit().GetConstant(); > int r2hi = r2.UpperLimit().GetConstant(); > > if (CheckedOps::MulOverflows(r1lo, r2lo, CheckedOps::Signed) || > CheckedOps::MulOverflows(r1lo, r2hi, CheckedOps::Signed) || > CheckedOps::MulOverflows(r1hi, r2lo, CheckedOps::Signed) || > CheckedOps::MulOverflows(r1hi, r2hi, CheckedOps::Signed)) > { > return Limit(Limit::keUnknown); > } > > int lo = min(min(r1lo * r2lo, r1lo * r2hi), min(r1hi * r2lo, r1hi * r2hi)); > int hi = max(max(r1lo * r2lo, r1lo * r2hi), max(r1hi * r2lo, r1hi * r2hi)); > assert(hi >= lo); > return Range(Limit(Limit::keConstant, lo), Limit(Limit::keConstant, hi)); > } > ``` > the problem that the original code for e.g. [-100..100] * [0..10] would return [0..1000] instead of [-1000..1000]. You can ignore "IsDependent" check here - it's not useful anyway. > > Add the JIT regression test for this case from issue (maintain the Fuzzlyn comment header in the test)</agent_instructions> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #124082 <!-- START COPILOT CODING AGENT TIPS --> --- 💡 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](https://gh.io/copilot-coding-agent-tips) in the docs. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com> Co-authored-by: Egor Bogatov <egorbo@gmail.com>
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.
diffs
Fixes #122288
Also, enables more branch foldings based on assertions - basically, mimics what SSA-based GetRange does, but based only on VNs.
I recommend reviewing with whitespaces disabled.