arm64: Remove widening casts before truncating#123546
arm64: Remove widening casts before truncating#123546jonathandavies-arm wants to merge 6 commits intodotnet:mainfrom
Conversation
|
@dotnet/arm64-contrib |
|
Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib |
- Remove Expect.cs
|
@jonathandavies-arm it looks like there are some superpmi failures, but I believe these are related to an issue that was resolved. Can you update your branch with the latest changes from main? |
|
/azp run Fuzzlyn |
|
Azure Pipelines successfully started running 1 pipeline(s). |
🤖 Copilot Code Review — PR #123546Holistic AssessmentMotivation: This PR eliminates unnecessary intermediate widening casts when a small-int cast (byte/short) is fed by an int→long widening cast. For example, Approach: The implementation identifies the pattern Summary: ✅ LGTM. The logic is sound and handles all signed/unsigned combinations correctly. The optimization is safe because truncation to small int types only preserves the lower 8 or 16 bits, which are invariant under 32-to-64 bit extension (whether sign-extended or zero-extended). The PR has already been approved by @EgorBo and passed Fuzzlyn testing. Detailed Findings✅ Correctness & SignednessThe optimization is mathematically correct for all combinations:
✅ Overflow Check Handling
✅ Implementation Details
✅ Test CoverageThe extensive test file
The tests validate both correctness (return values) and codegen (expected ARM64 instructions via FileCheck comments). Review performed with assistance from multiple AI models (Gemini 3 Pro). GPT-5.1-Codex timed out after 7+ minutes. |
|
/azp run Fuzzlyn |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This PR remove unnecessary casts instructions. I've added some examples below taken from the Casts.cs test file but I've seen the same optimisations when I run the asmdiffs.
Example 1
Arm64 Instruction Diff
-sxtw x0, w0 sxtb w0, w0x64 Instruction Diff
Example 2
Arm64 Instruction Diff
x64 Instruction Diff