Skip to content

winch(aarch64): Improve addressing modes#12708

Open
saulecabrera wants to merge 1 commit intobytecodealliance:mainfrom
saulecabrera:winch-improve-addressing-modes
Open

winch(aarch64): Improve addressing modes#12708
saulecabrera wants to merge 1 commit intobytecodealliance:mainfrom
saulecabrera:winch-improve-addressing-modes

Conversation

@saulecabrera
Copy link
Member

Prior to this commit, Winch's Address representation relied on the general (reg, offset) form for offset-based addressing, leaving the materialization of the addressing mode to Cranelift. This approach led to the following bug found by the fuzzer:

When offsets cannot be encoded as a 9-bit signed immediate offset or a 12-bit unsigned immediate offset with scaling, the offset must be loaded into a register and the addressing mode is transformed to its (reg, reg) form. Cranelift's addressing mode materialization currently uses x16 as a scratch register to load the offset; even though both Cranelift and Winch use x16 as a scratch register, its usage is not in sync, therefore clobbers can happen.

This commit improves addressing modes by requiring early materialization of addressing modes into their respective Cranelift variants.

Prior to this commit, Winch's `Address` representation relied on the
general `(reg, offset)` form for offset-based addressing, leaving the
materialization of the addressing mode to Cranelift. This approach led
to the following bug found by the fuzzer:

When offsets cannot be encoded as a 9-bit signed immediate offset or a
12-bit unsigned immediate offset with scaling, the offset must be
loaded into a register and the addressing mode is transformed to its
`(reg, reg)` form. Cranelift's addressing mode materialization currently
uses `x16` as a scratch register to load the offset; even though
both Cranelift and Winch use `x16` as a scratch register, its usage is
not in sync, therefore clobbers can happen.

This commit improves addressing modes by requiring early
materialization of addressing modes into their respective Cranelift
variants.
@saulecabrera saulecabrera requested review from a team as code owners March 3, 2026 18:01
@saulecabrera saulecabrera requested review from fitzgen and removed request for a team March 3, 2026 18:01
Comment on lines +324 to +325
let constant = self.add_constant(&imm.to_bytes());
let addr = AMode::Const { addr: constant };
Copy link
Member Author

Choose a reason for hiding this comment

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

I removed this from the top-level Address since it's only used here, which removes one level of indirection.

@github-actions github-actions bot added the winch Winch issues or pull requests label Mar 3, 2026
@github-actions
Copy link

github-actions bot commented Mar 3, 2026

Subscribe to Label Action

cc @saulecabrera

Details This issue or pull request has been labeled: "winch"

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

  • saulecabrera: winch

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

Learn more.

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

Labels

winch Winch issues or pull requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant