Skip to content

aarch64: remove MInst::Extend - #14793

Open
Rafferty97 wants to merge 3 commits into
bytecodealliance:mainfrom
Rafferty97:remove-sextend-aarm64
Open

Rafferty97 wants to merge 3 commits into
bytecodealliance:mainfrom
Rafferty97:remove-sextend-aarm64

Conversation

@Rafferty97

@Rafferty97 Rafferty97 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

My last PR (#14187) introduced MInst::BitfieldMove to represent all instances of the ubfm and sbfm instructions. As a result, zero- and sign-extensions can now be expressed as MInst::BitfieldMove or MInst::Mov directly, making the MInst::Extend variant redundant, so this PR removes it.

Changes

I have removed the MInst::Extend variant, and replaced sites that constructed it with calls to MInst::gen_extend,
which produces a MInst::BitfieldMove or MInst::Mov as necessary.

I've also reimplemented the extend helper function defined in ISLE in a similar fashion, and added a helper
in the process (u8_into_uimm6).

The code that performed code generation for MInst::Extend had special-cased the case where from_bits == 1,
producing an and instruction rather than a ubfm instruction on performance grounds. I haven't carried this over to the new gen_extend function as it would be unreachable in practice. (Claude tells me this is a relic from when boolean types like b1 existed and was now effectively dead code, but I haven't confirmed this myself.)

I've changed the test cases in codegen/src/isa/aarch64/inst/emit_tests.rs that exercised MInst::Extend
to use MInst::BitfieldMove instead, and removed the cases that lowered to different instructions, as those
cases should already be covered elsewhere. I also added a few extra cases with immr != 0 for better coverage.

To preserve the behaviour of print_with_state, I've added a special case to the MInst::BitfieldMove branch
that prints the appropriate aliases for ubfm/sbfm such that all the file tests still pass without adjustment.

Finally, in order to get isle/veri/isaspec/script/generate.sh -l to work, I had to replace a few
instances of std::fmt with core::fmt. This isn't related to these changes, so I can separate it into a separate PR if that's preferred.

Verification

In removing MInst::Extend, I necessarily also had to remove the code that generated the extend.isle spec file. To avoid a verification regression, I've added limited verification of MInst::BitfieldMove, restricted to just the cases needed for zero-/sign-extension.

This is also the part I'm most unsure about, so I'm more than open to feedback.

Future work

I dug a bit deeper into the optimisation of using and in place of ubfm when zero-extending a 1-bit input,
and it seems the rationale is sound and extends to zero-extending any input (other than 32-bit to 64-bit, which is a mov). It seems LLVM does this for all aarch64 targets, which is evidence that it's a worthwhile optimisation to consider for a future PR.

@Rafferty97
Rafferty97 requested a review from a team as a code owner October 17, 2026 06:44
@Rafferty97
Rafferty97 requested review from alexcrichton and removed request for a team October 17, 2026 06:44
@Rafferty97
Rafferty97 force-pushed the remove-sextend-aarm64 branch 2 times, most recently from 6f502f2 to 47df008 Compare October 17, 2026 07:55
@Rafferty97
Rafferty97 force-pushed the remove-sextend-aarm64 branch from 47df008 to fb9d752 Compare October 17, 2026 08:39
@Rafferty97
Rafferty97 force-pushed the remove-sextend-aarm64 branch from e18d652 to c2f1d73 Compare October 17, 2026 10:01
@github-actions github-actions Bot added cranelift Issues related to the Cranelift code generator cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:meta Everything related to the meta-language. isle Related to the ISLE domain-specific language winch Winch issues or pull requests labels Oct 17, 2026
@github-actions

Copy link
Copy Markdown

Subscribe to Label Action

cc @avanhatt, @cfallin, @fitzgen, @mmcloughlin, @saulecabrera

Details This issue or pull request has been labeled: "cranelift", "cranelift:area:aarch64", "cranelift:meta", "isle", "winch"

Thus the following users have been cc'd because of the following labels:

  • avanhatt: isle
  • cfallin: isle
  • fitzgen: isle
  • mmcloughlin: isle
  • saulecabrera: winch

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:meta Everything related to the meta-language. cranelift Issues related to the Cranelift code generator isle Related to the ISLE domain-specific language winch Winch issues or pull requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant