Uh oh!
There was an error while loading. Please reload this page.
Fold comparisons into single-value ranges in GetRangeFromAssertions - #123624
Conversation
Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib |
There was a problem hiding this comment.
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/RangeOpsto represent and compute the result of relational operators as[0..0],[1..1], or[0..1]ranges, including improved handling ofEQ/NEwhen operand ranges are disjoint or equal singletons. - Enhance
RangeCheck::GetRangeFromAssertionsto useGetRangeFromType, refine cast ranges using the source expression’s range, and to interpret comparison VNFs viaRangeOps::EvalRelop, with an early-exit when a single constant value is determined. - Update
optAssertionPropGlobal_RelOpto 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. |
Uh oh!
There was an error while loading. Please reload this page.
PTAL @jakobbotsch @dotnet/jit-contrib the last piece for now. Diffs CI was green once, now it's mostly deadlettering. |
hez2010
commented
Jan 29, 2026
It seems that this also mixed some regressions for example the bound check in |
EgorBo
commented
Jan 29, 2026
/ba-g deadletter |
This PR does:
[0..1], now it tries to fold it to[0..0](always false) or[1..1](always true)GT_EQ/GT_NEoperators when ranges are single-value constants.Diffs