Skip to content

JIT: Propagate rejectNegativeConst through lcl + cns in monotonicity check - #135851

Merged
EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:jit-fix-134454
Oct 16, 2026
Merged

EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:jit-fix-134454

Conversation

@EgorBo

@EgorBo EgorBo commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

For lcl + lcl, IsBinOpMonotonicallyIncreasing requires both operands to have non-negative seeds (rejectNegativeConst). But when an operand was itself lcl + cns, the check recursed with rejectNegativeConst = false, so in i += k; k = m + 2 the negative seed of m (-4) was accepted. i was treated as monotonically increasing and i < -2 was folded to false.

Fix: pass the caller's rejectNegativeConst through the lcl + cns case. No asm diffs in libraries.pmi.

Fixes #134454

A few diffs (correctness)

…check

For `lcl + lcl`, `IsBinOpMonotonicallyIncreasing` requires both operands to have
non-negative seeds (`rejectNegativeConst`). But when an operand was itself
`lcl + cns`, the check recursed with `rejectNegativeConst = false`, so in
`i += k; k = m + 2` the negative seed of `m` (-4) was accepted. `i` was treated
as monotonically increasing and `i < -2` was folded to false.

Fix: pass the caller's `rejectNegativeConst` through the `lcl + cns` case.
No asm diffs in libraries.pmi.

Fixes dotnet#134454

Co-authored-by: Copilot <[email protected]>
Copilot-Session: ef747772-3030-470e-b839-f9a4fc116717
@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.

🔵 Needs a closer look

Optimized regression execution remains unverified; human review should confirm failure before the fix and success afterward.

0 open findings

What changed in this PR

Fixes JIT monotonicity analysis for nested additions by preserving negative-seed rejection, addressing the incorrect comparison folding reported in #134454.

Changes:

  • Propagates rejectNegativeConst through local-plus-constant expressions.
  • Updates the helper declaration and call.
  • Adds a regression test expecting -3.
File Description
src/​tests/​JIT/​Regression_ro_2/​Runtime_134454.cs Adds the negative-seed regression test.
src/​coreclr/​jit/​rangecheck.h Adds the flag to the helper signature.
src/​coreclr/​jit/​rangecheck.cpp Preserves the flag during recursive analysis.

🧠 Review effort: Balanced

@EgorBo

EgorBo commented Oct 15, 2026

Copy link
Copy Markdown
Member Author

PTAL @dotnet/jit-contrib, trivial change, a few diffs

@EgorBo
EgorBo merged commit bc110ba into dotnet:main Oct 16, 2026
133 of 138 checks passed
@EgorBo
EgorBo deleted the jit-fix-134454 branch October 16, 2026 14:13
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 19, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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.

JIT: (bug) IsMonotonicallyIncreasing accepts a negative seed behind lcl + (lcl + cns), relop folded incorrectly

3 participants