Improve IntegralRange::ForCastOutput in assertion prop#128612
Draft
MihaZupan wants to merge 1 commit into
Draft
Conversation
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refines the JIT’s integral range analysis for certain non-overflowing casts by allowing IntegralRange::ForCastOutput to return a tighter range derived from the cast operand when it is provably within the cast’s default output range. This improves downstream assertion/range reasoning and can enable simpler codegen when the JIT can preserve non-negativity (and other range constraints) through casts.
Changes:
- Compute the cast’s default output range (
typeRange) for the relevant non-overflowing cast cases. - In non-MinOpts, compute the operand’s range and, when it’s contained within
typeRange, return the tighteroperandRangeinstead of the broader default.
Comment on lines
+539
to
+546
| if (!compiler->opts.MinOpts()) | ||
| { | ||
| return {SymbolicIntegerValue::Zero, SymbolicIntegerValue::UIntMax}; | ||
| // If the operand's range is tighter than the cast's range, use it instead. | ||
| IntegralRange operandRange = ForNode(cast->CastOp(), compiler); | ||
| if (typeRange.Contains(operandRange)) | ||
| { | ||
| return operandRange; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://gist.github.com/MihuBot/dea35dcc7a03aa6982f9cb187965a762
The diff in BigInteger is for a pattern like this
where the JIT didn't see
BitOperations.LeadingZeroCountas non-negative since it's implemented as(int)Lzcnt.X64.LeadingZeroCount(value).E.g.