Skip to content

More precise range assertions for GT_CNS_INT#130385

Draft
adamperlin wants to merge 2 commits into
dotnet:mainfrom
adamperlin:adamperlin/constant-range-assertions
Draft

More precise range assertions for GT_CNS_INT#130385
adamperlin wants to merge 2 commits into
dotnet:mainfrom
adamperlin:adamperlin/constant-range-assertions

Conversation

@adamperlin

Copy link
Copy Markdown
Contributor

Fixes #121400; We can use a simple binary search approach to narrow the upper bound for GT_CNS_INT type nodes in assertionprop. Credit for the approach to the comment here: #120980 (comment)

Copilot AI review requested due to automatic review settings July 8, 2026 23:09
@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 8, 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

This PR refines the range computation for integral constant nodes (GT_CNS_INT/GT_CNS_LNG) in JIT assertion propagation by selecting a narrower rangeType based on the constant’s magnitude, enabling tighter derived non-negative range assertions.

Changes:

  • Replace coarse FitsIn<int32_t>/FitsIn<uint32_t> range typing with a more granular threshold-based selection (8/16/32-bit signed/unsigned) for constants.
  • Use the selected narrower type’s maximum to tighten the inferred upper bound when the constant is known non-negative.

Comment on lines 291 to +295
int64_t constValue = node->AsIntConCommon()->IntegralValue();

if (FitsIn<int32_t>(constValue))
if (constValue <= UINT16_MAX)
{
rangeType = TYP_INT;
if (constValue <= UINT8_MAX)
Copilot AI review requested due to automatic review settings July 9, 2026 16: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 1 out of 1 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/coreclr/jit/assertionprop.cpp:346

  • The GT_CNS_INT/GT_CNS_LNG switch case no longer returns or breaks after computing rangeType. This causes an unintended fallthrough into case GT_QMARK, where node->AsQmark() will be called on a constant node (invalid cast / potential crash). Add the missing return (or a break plus an appropriate return) after selecting the tighter rangeType.
        }

        case GT_QMARK:
            return Union(ForNode(node->AsQmark()->ThenNode(), compiler),
                         ForNode(node->AsQmark()->ElseNode(), compiler));

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.

Enhance Range Assertions for GT_CNS_INT

2 participants