More precise range assertions for GT_CNS_INT#130385
Draft
adamperlin wants to merge 2 commits 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 range computation for integral constant nodes (GT_CNS_INT/GT_CNS_LNG) in JIT assertion propagation by selecting a narrower rangeType based on the constant’s magnitude, enabling tighter derived non-negative range assertions.
Changes:
- Replace coarse
FitsIn<int32_t>/FitsIn<uint32_t>range typing with a more granular threshold-based selection (8/16/32-bit signed/unsigned) for constants. - Use the selected narrower type’s maximum to tighten the inferred upper bound when the constant is known non-negative.
Comment on lines
291
to
+295
| int64_t constValue = node->AsIntConCommon()->IntegralValue(); | ||
|
|
||
| if (FitsIn<int32_t>(constValue)) | ||
| if (constValue <= UINT16_MAX) | ||
| { | ||
| rangeType = TYP_INT; | ||
| if (constValue <= UINT8_MAX) |
This was referenced Jul 9, 2026
Open
Open
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/coreclr/jit/assertionprop.cpp:346
- The
GT_CNS_INT/GT_CNS_LNGswitch case no longer returns or breaks after computingrangeType. This causes an unintended fallthrough intocase GT_QMARK, wherenode->AsQmark()will be called on a constant node (invalid cast / potential crash). Add the missingreturn(or abreakplus an appropriate return) after selecting the tighterrangeType.
}
case GT_QMARK:
return Union(ForNode(node->AsQmark()->ThenNode(), compiler),
ForNode(node->AsQmark()->ElseNode(), compiler));
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.
Fixes #121400; We can use a simple binary search approach to narrow the upper bound for GT_CNS_INT type nodes in assertionprop. Credit for the approach to the comment here: #120980 (comment)