Skip to content

x64: Move insertlane to ISLE#3544

Merged
alexcrichton merged 1 commit intobytecodealliance:mainfrom
alexcrichton:fix-movsd-issue
Nov 18, 2021
Merged

x64: Move insertlane to ISLE#3544
alexcrichton merged 1 commit intobytecodealliance:mainfrom
alexcrichton:fix-movsd-issue

Conversation

@alexcrichton
Copy link
Copy Markdown
Member

This also fixes a bug where movsd was incorrectly used with a memory
operand for insertlane, causing it to actually zero the upper bits
instead of preserving them.

Note that the insertlane logic still exists in lower.rs because it's
used as a helper for a few other instruction lowerings which aren't
migrated to ISLE yet. This commit also adds a helper in ISLE itself for
those other lowerings to use when they get implemented.

Closes #3216

@alexcrichton alexcrichton changed the title Move insertlane to ISLE x64: Move insertlane to ISLE Nov 18, 2021
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:x64 Issues related to x64 codegen isle Related to the ISLE domain-specific language labels Nov 18, 2021
@github-actions
Copy link
Copy Markdown

Subscribe to Label Action

cc @cfallin, @fitzgen

Details This issue or pull request has been labeled: "cranelift", "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.


;;;; Rules for `insertlane` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(rule (lower (insertlane vec @ (value_type ty) val (u8_from_uimm8 idx)))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It occurs to me looking at this that I should have originally put a debug_assert in the lowering code to check for correct indexes; I don't really think this PR needs to change but I'm curious--if we did want to check that the index was in range for the type, how would we do so in ISLE?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't think that a debug_asert! would directly translate but what could be done is to have a different extractor here instead of u8_from_uimm8 but rather something like u{1,2,3,4}_from_uimm8 where the rule wouldn't get matched if the index was out-of-bounds, and then later we'd have a codegen error of "ISLE didn't match this" and manual inspection would show that the lane index was out-of-bounds. @fitzgen may have other ideas though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok, cool; thanks, just curious.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The right way would probably be to assert in Rust code called by the rule; either in one of the extractors in the pattern (make a specific LaneIndex type then a (lane_index_from_uimm8 idx) extractor pattern that returns it?) or in the constructor of whatever instruction takes it.

We could also have a generic (assert ...) constructor that we could invoke in the right-hand side but that seems like a bit of an antipattern; better to just encode the invariant in the types :-)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seconding what @cfallin said :)

;; two `movsd` instructions. The first `movsd` (used as `xmm_unary_rm_r`) will
;; load from memory into a temp register and then the second `movsd` (modeled
;; internally as `xmm_rm_r` will merge the temp register into our `vec`
;; register.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

This also fixes a bug where `movsd` was incorrectly used with a memory
operand for `insertlane`, causing it to actually zero the upper bits
instead of preserving them.

Note that the insertlane logic still exists in `lower.rs` because it's
used as a helper for a few other instruction lowerings which aren't
migrated to ISLE yet. This commit also adds a helper in ISLE itself for
those other lowerings to use when they get implemented.

Closes bytecodealliance#3216
@github-actions github-actions bot added cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:aarch64 Issues related to AArch64 backend. labels Nov 18, 2021
@alexcrichton alexcrichton merged commit 352ee2b into bytecodealliance:main Nov 18, 2021
@alexcrichton alexcrichton deleted the fix-movsd-issue branch November 18, 2021 19:48
jlb6740 pushed a commit to jlb6740/wasmtime that referenced this pull request Nov 19, 2021
This also fixes a bug where `movsd` was incorrectly used with a memory
operand for `insertlane`, causing it to actually zero the upper bits
instead of preserving them.

Note that the insertlane logic still exists in `lower.rs` because it's
used as a helper for a few other instruction lowerings which aren't
migrated to ISLE yet. This commit also adds a helper in ISLE itself for
those other lowerings to use when they get implemented.

Closes bytecodealliance#3216
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.

x64 simd: Incorrect codegen leads to wrong result

4 participants