[ARM64] Only extend if src size is less than target - #7307
Conversation
|
|
|
There's a possibility that this winds up influencing types of temp registers due to spills in a way that is actually useful so I need to check on that a bit once I push some other stuff before accepting |
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes ARM64 intermediate language (IL) generation by eliminating unnecessary zero-extend and sign-extend operations when the source and target sizes are equal. The changes reduce the IL instruction count by approximately 700 extensions in ARM64 ntdll.
Key changes:
- Conditionally emit extensions in load instructions only when the load size is smaller than the target register size
- Remove unnecessary zero-extend operations from FMOV instructions when source and destination are the same size
- Remove redundant zero-extend wrappers from UBFX/UBFIZ bit-field operations
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ILSETREG_O(operand1, il.ShiftLeft(REGSZ_O(operand2), | ||
| il.And(REGSZ_O(operand2), | ||
| ILREG_O(operand2), | ||
| il.Const(REGSZ_O(operand2), (1LL << IMM_O(operand4)) - 1)), | ||
| il.Const(1, IMM_O(operand3))))); |
There was a problem hiding this comment.
Inconsistent indentation: the continuation lines use spaces aligned to the opening parenthesis on line 3741, but the first parameter on line 3742 is indented too far to the right. Line 3742 should align with 'REGSZ_O(operand2)' on line 3741.
| il.LogicalShiftRight(REGSZ_O(operand2), | ||
| ILREG_O(operand2), | ||
| il.Const(1, IMM_O(operand3))), | ||
| il.Const(REGSZ_O(operand2), (1LL << IMM_O(operand4)) - 1)))); |
There was a problem hiding this comment.
Inconsistent indentation: the continuation lines starting at 3759 are indented too far to the right. They should align with the 'il.And' call on line 3758 for consistency with the project's formatting style.
| il.LogicalShiftRight(REGSZ_O(operand2), | |
| ILREG_O(operand2), | |
| il.Const(1, IMM_O(operand3))), | |
| il.Const(REGSZ_O(operand2), (1LL << IMM_O(operand4)) - 1)))); | |
| il.LogicalShiftRight(REGSZ_O(operand2), | |
| ILREG_O(operand2), | |
| il.Const(1, IMM_O(operand3))), | |
| il.Const(REGSZ_O(operand2), (1LL << IMM_O(operand4)) - 1)))); |
Shink expr tree sizes with equivalent semantics. Developed on top of #7296 for my convenience.
This changes 3ish instructions:
ENC_FMOV_64VX_FLOAT2INTcase, but the comment indecode_scratchpatdindicates it's only used with 64 bit registers.This removes about 700 total extensions from an arm64 ntdll.
Also added this check to the liftcheck wishlist in #2612