Skip to content

Remove 'rng.LowerLimit().AddConstant(cns);'#120233

Merged
EgorBo merged 2 commits intodotnet:mainfrom
EgorBo:fix-optAssertionProp_RangeProperties
Sep 30, 2025
Merged

Remove 'rng.LowerLimit().AddConstant(cns);'#120233
EgorBo merged 2 commits intodotnet:mainfrom
EgorBo:fix-optAssertionProp_RangeProperties

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Sep 29, 2025

Fixes #119710

When we want to see if the expression (X + CNS) is never negative, we get X's range and then Add CNS to it (for both lower and upper bound). It seems like we add the lower one twice because it's supposed to be done only once here:

            if ((rng.LowerLimit().IsConstant() && !rng.LowerLimit().AddConstant(cns)) ||
                (rng.UpperLimit().IsConstant() && !rng.UpperLimit().AddConstant(cns)))

seems to be some copy-paste mistake and I'm surprised it it showed up only now (was exposed by #119474)

Surprisingly, there are jit-diff improvements from not adding the constant twice to the lower bound: diffs

@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 Sep 29, 2025
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@EgorBo EgorBo marked this pull request as ready for review September 30, 2025 11:37
Copilot AI review requested due to automatic review settings September 30, 2025 11:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug in the JIT compiler's assertion propagation range analysis where a constant was being added twice to the lower bound of a range. The fix removes a redundant line that was mistakenly adding the constant to the lower limit before the actual range check logic.

  • Removes duplicate constant addition to range lower bound in assertion propagation
  • Adds regression test to prevent future occurrences of this bug

Reviewed Changes

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

File Description
src/coreclr/jit/assertionprop.cpp Removes the redundant rng.LowerLimit().AddConstant(cns); line that was incorrectly modifying the range before validation
src/tests/JIT/Regression/JitBlue/Runtime_119710/Runtime_119710.cs Adds regression test case that would fail with the bug present
src/tests/JIT/Regression/JitBlue/Runtime_119710/Runtime_119710.csproj Project file for the regression test

@EgorBo EgorBo merged commit 0231cbf into dotnet:main Sep 30, 2025
119 checks passed
@EgorBo EgorBo deleted the fix-optAssertionProp_RangeProperties branch September 30, 2025 11:37
@github-actions github-actions bot locked and limited conversation to collaborators Oct 31, 2025
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: Wrong results with comparison

3 participants