aarch64: lower ishl + ushr/sshr pairs to a single ubfm/sbfm instruction - #14187
Open
Rafferty97 wants to merge 4 commits into
Open
aarch64: lower ishl + ushr/sshr pairs to a single ubfm/sbfm instruction#14187Rafferty97 wants to merge 4 commits into
ishl + ushr/sshr pairs to a single ubfm/sbfm instruction#14187Rafferty97 wants to merge 4 commits into
Conversation
eligible `ishl`/`sshr` pairs into one `sbfm` instruction.
methods `sbfm_immr`/`sbfm_imms`; added additional test cases
Subscribe to Label ActionDetailsThis issue or pull request has been labeled: "cranelift", "cranelift:area:aarch64", "isle"Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
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.
Motivation
AArch64 can express a left-shift followed by a right-shift as a single bitfield-move instruction, either
ubfmorsbfm, which are commonly aliased tosbfx/sbfiz/ubfx/ubfiz. The aarch64 backend currently emits two instructions, since no rule inspects a sshr/ushr's operand for a producing ishl. The appropriate encoder already exists inemit.rsas the functionenc_bfm, but only servesMInst::Extend, which only covers fixed-width sign extension.There has been previous discussion around adding support for this kind of lowering here: #1067
Changes
I've added
MInst::BitfieldMoveto express the bitfield move family of AArch64 instructions (bfm, ubfm, sbfm) more generally than the pre-existingMInst::Extend. I then added lowering rules to recognise a sequence ofishl+ushrorishl+sshroperations that could be lowered toubfmorsbfmrespectively. This necessitated two helper functions (sbfm_immrandsbfm_imms) to calculate the appropriate values for theimmrandimmsimmediates.I have taken care to support both 32-bit and 64-bit instructions, and to mask off the shift amounts as required by CLIF's semantics. I've added tests to
shift-rotate.clifthat cover all these cases.I've also lightly modified the
enc_bfmfunction signature to take aBfmOprather than raw bits, for better separation of concerns.Future work
Now that
MInstcan represent the full suite of bitfield-move instructions precisely, there's an argument for removing theExtendvariant and instead lowering zero- and sign-extension operations toBitfieldMovedirectly. To bound the scope of this PR, though, I've left it in place.