Skip to content

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Jan 26, 2026

This PR does:

  1. More precise Range for VNF_Cast. previously it was whatever CastTo provided, now it also inspects the CastOp (and if its Range is within or smaller than CastTo - use that).
  2. More precise Range for relops (e.g. VNF_GT). Previously it was always [0..1], now it tries to fold it to [0..0] (always false) or [1..1] (always true)
  3. Improved RangeOps::EvalRelop for GT_EQ/GT_NE operators when ranges are single-value constants.
  4. Small cleanups, TP-oriented changes.

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 Jan 26, 2026
@dotnet-policy-service
Copy link
Contributor

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

@EgorBo EgorBo marked this pull request as ready for review January 27, 2026 14:27
Copilot AI review requested due to automatic review settings January 27, 2026 14:27
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 refines range analysis and assertion propagation so that relational comparisons can often be recognized as always-true or always-false, allowing more branches to be folded.

Changes:

  • Extend Range/RangeOps to represent and compute the result of relational operators as [0..0], [1..1], or [0..1] ranges, including improved handling of EQ/NE when operand ranges are disjoint or equal singletons.
  • Enhance RangeCheck::GetRangeFromAssertions to use GetRangeFromType, refine cast ranges using the source expression’s range, and to interpret comparison VNFs via RangeOps::EvalRelop, with an early-exit when a single constant value is determined.
  • Update optAssertionPropGlobal_RelOp to use range information for the entire relop VN (instead of separate operand ranges) and fold comparisons directly when their range is a single constant 0 or 1.

Reviewed changes

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

File Description
src/coreclr/jit/rangecheck.h Adds Range::IsSingleValueConstant and changes RangeOps::EvalRelop to return a Range capturing 0/1 semantics instead of a tri-state enum; RangeCheck::GetRangeFromType is made static.
src/coreclr/jit/rangecheck.cpp Refactors GetRangeFromAssertions to use GetRangeFromType for casts, use EvalRelop for VN comparison functions, early-return for single-value ranges, and slightly restructures the reaching-assertions visitor.
src/coreclr/jit/assertionprop.cpp Switches global relop assertion propagation to query the range of the relop’s value number and fold to true/false when the computed range is a single constant 0 or 1.

@EgorBo
Copy link
Member Author

EgorBo commented Jan 27, 2026

PTAL @jakobbotsch @dotnet/jit-contrib the last piece for now. Diffs

CI was green once, now it's mostly deadlettering.

@EgorBo EgorBo requested a review from jakobbotsch January 27, 2026 14:31
@hez2010
Copy link
Contributor

hez2010 commented Jan 29, 2026

It seems that this also mixed some regressions for example the bound check in Microsoft.CodeAnalysis.LittleEndianReader:ReadUInt32 is no longer being folded away?

@EgorBo
Copy link
Member Author

EgorBo commented Jan 29, 2026

/ba-g deadletter

@EgorBo EgorBo merged commit 8f18ed8 into dotnet:main Jan 29, 2026
119 of 126 checks passed
@EgorBo EgorBo deleted the fold-cmp-from-assertions branch January 29, 2026 10:32
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 reduce-unsafe

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants