Skip to content

Remove redundant checked contexts around casts + more bounds checks#124184

Merged
EgorBo merged 5 commits intodotnet:mainfrom
EgorBo:clear-overflow-flag-casts
Feb 11, 2026
Merged

Remove redundant checked contexts around casts + more bounds checks#124184
EgorBo merged 5 commits intodotnet:mainfrom
EgorBo:clear-overflow-flag-casts

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Feb 9, 2026

Example of a removed checked context:

public static byte Test(uint a)
{
    if (a > 100)
        return 0;
    return checked((byte)a); // checked is redundant here
}

Diffs

Copilot AI review requested due to automatic review settings February 9, 2026 16:54
@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 Feb 9, 2026
@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.

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 extends JIT assertion-based reasoning to (1) remove redundant overflow checks/casts when proven safe by range info and (2) enable additional bounds-check eliminations from inferred constant ranges.

Changes:

  • Promote RangeCheck::GetRangeFromType to be callable from assertion propagation, enabling range comparisons for cast redundancy decisions.
  • Enhance MergeEdgeAssertions to infer arr.Length > 0 from certain non-constant index assertions.
  • Add range-based bounds check elimination and adjust assertion-based non-negative/non-zero inference.

Reviewed changes

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

File Description
src/coreclr/jit/rangecheck.h Exposes GetRangeFromType for external (assertionprop) range reasoning.
src/coreclr/jit/rangecheck.cpp Improves edge-assertion merge logic, including deducing Length > 0 in more cases.
src/coreclr/jit/assertionprop.cpp Uses range reasoning to remove redundant casts/overflow checks and drop more bounds checks.

@EgorBo
Copy link
Member Author

EgorBo commented Feb 9, 2026

/azp run Fuzzlyn

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

@EgorBo
Copy link
Member Author

EgorBo commented Feb 11, 2026

PTAL @jakobbotsch @dotnet/jit-contrib

@EgorBo EgorBo requested a review from jakobbotsch February 11, 2026 12:05
@EgorBo EgorBo enabled auto-merge (squash) February 11, 2026 14:11
@EgorBo EgorBo merged commit 23c8cd9 into dotnet:main Feb 11, 2026
127 of 132 checks passed
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.

2 participants