Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some 16- and 8-bit behavior in x64 backend related to rotates. #3610

Merged
merged 2 commits into from
Dec 16, 2021

Conversation

cfallin
Copy link
Member

@cfallin cfallin commented Dec 16, 2021

Uncovered by @bjorn3 (thanks!): 8- and 16-bit rotates were not working
properly in recent versions of Cranelift with part of the lowering
migrated to ISLE.

This PR fixes a few issues:

  • 8- and 16-bit rotate-left needs to mask a constant amount, if any,
    because we use a 32-bit rotate instruction and so don't get the
    appropriate shift-amount masking for free from x86 semantics.

  • operand_size_from_type was incorrect: it only handled 32- and 64-bit
    types and silently returned OperandSize::Size32 for everything else.
    Now uses the OperandSize::from_ty(ty) helper as the pre-ISLE code
    did.

Our test coverage for narrow value types is not great; this PR adds some
runtests for rotl/rotr but more would always be better!

Uncovered by @bjorn3 (thanks!): 8- and 16-bit rotates were not working
properly in recent versions of Cranelift with part of the lowering
migrated to ISLE.

This PR fixes a few issues:

- 8- and 16-bit rotate-left needs to mask a constant amount, if any,
  because we use a 32-bit rotate instruction and so don't get the
  appropriate shift-amount masking for free from x86 semantics.

- `operand_size_from_type` was incorrect: it only handled 32- and 64-bit
  types and silently returned `OperandSize::Size32` for everything else.
  Now uses the `OperandSize::from_ty(ty)` helper as the pre-ISLE code
  did.

Our test coverage for narrow value types is not great; this PR adds some
runtests for rotl/rotr but more would always be better!
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:x64 Issues related to x64 codegen isle Related to the ISLE domain-specific language labels Dec 16, 2021
@github-actions
Copy link

Subscribe to Label Action

cc @cfallin, @fitzgen

This issue or pull request has been labeled: "cranelift", "cranelift:area:aarch64", "cranelift:area:machinst", "cranelift:area:x64", "isle"

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

  • cfallin: isle
  • fitzgen: isle

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

Learn more.

@cfallin cfallin merged commit e1e2f3c into bytecodealliance:main Dec 16, 2021
@cfallin cfallin deleted the fix-narrow-type-rotate branch December 16, 2021 22:06
@bjorn3
Copy link
Contributor

bjorn3 commented Dec 17, 2021

I can confirm this fixes rotate in cg_clif.

@cfallin cfallin mentioned this pull request Dec 17, 2021
bjorn3 added a commit to rust-lang/rustc_codegen_cranelift that referenced this pull request Dec 17, 2021
This reverts commit a1037fa.

There are two regressions in Cranelift with respect to small integer
operations. Both have already been fixed on thebmain branch, but we will
have to wait for a new Cranelift release. They have been fixed by
bytecodealliance/wasmtime#3610 and bytecodealliance/wasmtime#3617.
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:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:x64 Issues related to x64 codegen cranelift Issues related to the Cranelift code generator isle Related to the ISLE domain-specific language
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants