-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Fold comparisons into single-value ranges in GetRangeFromAssertions #123624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib |
…p-from-assertions
…1 into fold-cmp-from-assertions
There was a problem hiding this 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/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. |
|
PTAL @jakobbotsch @dotnet/jit-contrib the last piece for now. Diffs CI was green once, now it's mostly deadlettering. |
|
It seems that this also mixed some regressions for example the bound check in |
|
/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