Skip to content

Conversation

@cfallin
Copy link
Member

@cfallin cfallin commented May 7, 2025

This PR addresses an underlying limitation that became a problem for Cranelift recently, after folding return-value loads into call pseudoinsts (thus producing single instructions with many operands): we only supported 255 operands per instruction.

It appears that Use was using a u8 for the "slot index" for an operand as a result of earlier optimization/packing efforts. However, the current shape of the struct leaves a padding byte free, so we should be able to expand to a u16 with no loss in performance.

Furthermore, previously we weren't catching the overflow, but rather were silently wrapping around (eek). This properly returns a RegAllocError::TooManyOperands now if an instruction has too many operands (more than u16::MAX).

This PR addresses an underlying limitation that became a problem for
Cranelift recently, after folding return-value loads into call
pseudoinsts (thus producing single instructions with many operands): we
only supported 255 operands per instruction.

It appears that `Use` was using a `u8` for the "slot index" for an
operand as a result of earlier optimization/packing efforts. However,
the current shape of the struct leaves a padding byte free, so we should
be able to expand to a `u16` with no loss in performance.

Furthermore, previously we weren't catching the overflow, but rather
were silently wrapping around (eek). This properly returns a
`RegAllocError::TooManyOperands` now if an instruction has too many
operands (more than `u16::MAX`).
@cfallin cfallin force-pushed the handle-too-many-operands-and-support-more-of-them branch from 5f25684 to 8de33da Compare May 7, 2025 19:20
Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

Good catch!

@cfallin cfallin merged commit 46b284d into bytecodealliance:main May 7, 2025
6 checks passed
@cfallin cfallin deleted the handle-too-many-operands-and-support-more-of-them branch May 7, 2025 20:07
cfallin added a commit to cfallin/regalloc2 that referenced this pull request May 7, 2025
Includes fix from bytecodealliance#226 for instructions with more than `u8::MAX`
operands.
@cfallin cfallin mentioned this pull request May 7, 2025
cfallin added a commit that referenced this pull request May 7, 2025
Includes fix from #226 for instructions with more than `u8::MAX`
operands.
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.

2 participants