Skip to content

Fix range-check monotonicity for multiplication#130426

Merged
EgorBo merged 5 commits into
dotnet:mainfrom
EgorBo:runtime-130425-regression-test
Jul 12, 2026
Merged

Fix range-check monotonicity for multiplication#130426
EgorBo merged 5 commits into
dotnet:mainfrom
EgorBo:runtime-130425-regression-test

Conversation

@EgorBo

@EgorBo EgorBo commented Jul 9, 2026

Copy link
Copy Markdown
Member

Range analysis treated multiplication and left shifts as monotonically increasing even though both operations can decrease negative values. This could widen an invalid range and incorrectly fold comparisons.

Conservatively restrict monotonic widening to addition. SuperPMI benchmarks.run showed zero asm diffs compared with the more precise fix. Adds a regression test for the reported miscompile.

Fixes #130425.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3f1f7aae-af73-4d20-8036-8fc58daa4f21
Copilot AI review requested due to automatic review settings July 9, 2026 18:48
@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 Jul 9, 2026
@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.

Pull request overview

Adds a new JIT regression test under src/tests/JIT/Regression/JitBlue and wires it into the merged regression test project, covering a miscompile scenario around negative induction variables multiplied by 2.

Changes:

  • Added Runtime_130425 regression test implemented as a merged-runner test using xUnit assertions.
  • Updated Regression_ro_2.csproj to compile the new test source file.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/tests/JIT/Regression/Regression_ro_2.csproj Includes the new Runtime_130425 test source in the merged regression project.
src/tests/JIT/Regression/JitBlue/Runtime_130425/Runtime_130425.cs New regression test validating the expected result for the problematic loop/range-analysis scenario.

Propagate non-negative requirements from multiplication and left shifts back to loop initial values before widening their ranges.

Fixes dotnet#130425

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3f1f7aae-af73-4d20-8036-8fc58daa4f21
Copilot AI review requested due to automatic review settings July 9, 2026 19:04
@EgorBo EgorBo changed the title Add regression test for Runtime_130425 Fix range-check monotonicity for multiplication Jul 9, 2026

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread src/coreclr/jit/rangecheck.cpp Outdated
Comment thread src/coreclr/jit/rangecheck.cpp Outdated
Conservatively stop treating multiplication and left shifts as monotonically increasing. SuperPMI benchmarks show no asm diffs from the more precise fix.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3f1f7aae-af73-4d20-8036-8fc58daa4f21
Copilot AI review requested due to automatic review settings July 9, 2026 19:22

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread src/coreclr/jit/rangecheck.cpp Outdated
Comment thread src/coreclr/jit/rangecheck.cpp
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 9, 2026 19:33

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@EgorBo

EgorBo commented Jul 10, 2026

Copy link
Copy Markdown
Member Author

PTAL @dotnet/jit-contrib AI-found fix for a potential correctness issue with a repro. minimal diffs

Instead of attempting to fix the monotonically-increased logic for GT_MUL, GT_LSH I just disabled it for them, left only correct GT_ADD

@EgorBo EgorBo requested a review from a team July 10, 2026 12:49
Comment thread src/coreclr/jit/rangecheck.cpp Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 04aea4d9-a12d-4589-a2cd-426e4af339c8
Copilot AI review requested due to automatic review settings July 10, 2026 16:42

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Comment thread src/coreclr/jit/rangecheck.cpp
@EgorBo

EgorBo commented Jul 12, 2026

Copy link
Copy Markdown
Member Author

/ba-g infra issues

@EgorBo EgorBo merged commit 26911b9 into dotnet:main Jul 12, 2026
136 of 143 checks passed
@EgorBo EgorBo deleted the runtime-130425-regression-test branch July 12, 2026 12:02
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

Development

Successfully merging this pull request may close these issues.

rangecheck bug around GT_MUL / GT_LSH

4 participants