[clr-interp] Fix implicit promotion of I4 to I#122319
Merged
davidwrighton merged 11 commits intodotnet:mainfrom Dec 10, 2025
Merged
[clr-interp] Fix implicit promotion of I4 to I#122319davidwrighton merged 11 commits intodotnet:mainfrom
davidwrighton merged 11 commits intodotnet:mainfrom
Conversation
…allow for more useful optimization tests
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes implicit promotion of I4 (int32) to I (native int) in the CoreCLR interpreter to match RyuJIT's behavior. The fix addresses inconsistencies where some opcodes use zero-extension and others use sign-extension when promoting 32-bit integers to native integers on 64-bit platforms.
- Adds a new helper function to determine the correct widening operation (sign or zero extension) based on the opcode
- Implements comprehensive tests for all opcodes that perform implicit promotion, covering arithmetic, comparison, and branch operations
- Tests verify correct behavior for unsigned overflow operations (add.ovf.un, sub.ovf.un, mul.ovf.un) and unsigned branch/comparison operations (bne.un, blt.un, etc.)
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/interpreter/compiler.cpp | Adds InterpOpForWideningArgForImplicitUpcast() to select appropriate conversion (sign vs zero extension) and updates EmitTwoArgBranch() and EmitBinaryArithmeticOp() to use it |
| src/tests/JIT/Methodical/int64/unsigned/implicit_promotion_il.il | New IL assembly defining 52 operator methods testing all promotion scenarios with mixed I4/I8 operands |
| src/tests/JIT/Methodical/int64/unsigned/implicit_promotion_il.ilproj | Project file for the IL test |
| src/tests/JIT/Methodical/int64/unsigned/implicit_promotion.cs | New C# test invoking IL operators with negative values to validate sign/zero extension behavior on 32-bit vs 64-bit platforms |
| src/tests/JIT/Methodical/Methodical_*.csproj | Updates to include the new test files in various build configurations |
src/tests/JIT/Methodical/int64/unsigned/implicit_promotion_il.il
Outdated
Show resolved
Hide resolved
src/tests/JIT/Methodical/int64/unsigned/implicit_promotion_il.il
Outdated
Show resolved
Hide resolved
Contributor
|
Tagging subscribers to this area: @BrzVlad, @janvorli, @kg |
This was referenced Dec 9, 2025
janvorli
approved these changes
Dec 9, 2025
Member
janvorli
left a comment
There was a problem hiding this comment.
LGTM modulo the copilot nits that seem to make sense.
Co-authored-by: Copilot <[email protected]>
3 tasks
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Ryujit does implicit promotion using zero-extending promotions for some opcode and sign extending for others. I don't see a particularly good rhyme or reason for the current behavior, but it does not match what the interpreter does.
This PR adds a test for all the opcodes that experience promotion, and attempts to test all the behaviors correctly. In building it, several issues were found/fixed.
This is known to fix the GitHub13501 test. in addition to the various issues found during test development.