Skip to content

Conversation

@yrp604
Copy link
Contributor

@yrp604 yrp604 commented Aug 24, 2025

Shink expr tree sizes with equivalent semantics. Developed on top of #7296 for my convenience.

This changes 3ish instructions:

  • ldr variants -- conditionally emit the zero/sign extension when needed.
  • fmov variants -- conditionally emit the zero extension when needed. I don't think there is existing test coverage for the ENC_FMOV_64VX_FLOAT2INT case, but the comment in decode_scratchpatd indicates it's only used with 64 bit registers.
  • ubfx/ubfiz -- there are no encodings where the second argument is a different size than the first.

This removes about 700 total extensions from an arm64 ntdll.

Also added this check to the liftcheck wishlist in #2612

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@yrp604 yrp604 changed the title [ARM64] Only extend loads if src size is less than target [ARM64] Only extend if src size is less than target Aug 25, 2025
@plafosse plafosse added this to the Io milestone Sep 8, 2025
@rssor
Copy link
Member

rssor commented Sep 9, 2025

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

@plafosse plafosse requested a review from Copilot October 28, 2025 12:49
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +3741 to +3745
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)))));
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +3759 to +3762
il.LogicalShiftRight(REGSZ_O(operand2),
ILREG_O(operand2),
il.Const(1, IMM_O(operand3))),
il.Const(REGSZ_O(operand2), (1LL << IMM_O(operand4)) - 1))));
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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))));

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants