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

riscv64: Add support for load+extend patterns #8765

Merged
merged 2 commits into from
Jun 11, 2024

Conversation

afonso360
Copy link
Contributor

👋 Hey,

This PR adds support for merging {s,u}extend instructions into a preceding load.

RISC-V doesn't have sinkable loads per se, but the regular load instructions sign / zero extend the loaded values by default. So here we model that by pretending that that is a sinkable load on an extend instruction.

This PR is also a part of #6056. I'm working on that, the first step is to support generating the same code with load+extend on all backends as we currently do with the specialized {u,s}loadNN instructions.

RISC-V doesen't have sinkable loads per se, but the regular load
instructions support sign / zero extending the loaded values.

We model those here as a sinkable load on the extend instruction.
@afonso360 afonso360 added cranelift Issues related to the Cranelift code generator cranelift:area:riscv64 Issues related to the RISC-V 64 backend. labels Jun 10, 2024
@afonso360 afonso360 requested a review from a team as a code owner June 10, 2024 21:08
@afonso360 afonso360 requested review from fitzgen and removed request for a team June 10, 2024 21:08
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.

Very nice!

Comment on lines +2427 to +2436
;; Extract a sinkable instruction from a value operand.
(decl sinkable_inst (Inst) Value)
(extern extractor sinkable_inst sinkable_inst)

;; Matches a sinkable load.
(decl sinkable_load (Inst Type MemFlags Value Offset32) Value)
(extractor (sinkable_load inst ty flags addr offset)
(and
(load flags addr offset)
(sinkable_inst (has_type ty inst))))
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a comment here about the extend(load()) use case and the asterisk around "sinkable" that you added in the PR description? That seems like good context to have when reading this code.

@github-actions github-actions bot added the isle Related to the ISLE domain-specific language label Jun 10, 2024
Copy link

Subscribe to Label Action

cc @cfallin, @fitzgen

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

@afonso360 afonso360 enabled auto-merge June 11, 2024 09:06
@afonso360 afonso360 added this pull request to the merge queue Jun 11, 2024
Merged via the queue into bytecodealliance:main with commit 9e34bde Jun 11, 2024
36 checks passed
@afonso360 afonso360 deleted the riscv-load-sink branch June 11, 2024 09:32
afonso360 added a commit to afonso360/wasmtime that referenced this pull request Jun 11, 2024
This commit adds support for merging a load with a `{u,s}extend` instruction. On AArch64 the load instructions already do this by default, so we can just emit the regular loads.

See also bytecodealliance#8765 that does a similar thing for RISC-V
afonso360 added a commit to afonso360/wasmtime that referenced this pull request Jun 11, 2024
This commit adds support for merging a load with a `{u,s}extend` instruction. On AArch64 the load instructions already do this by default, so we can just emit the regular loads.

See also bytecodealliance#8765 that does a similar thing for RISC-V
github-merge-queue bot pushed a commit that referenced this pull request Jun 11, 2024
This commit adds support for merging a load with a `{u,s}extend` instruction. On AArch64 the load instructions already do this by default, so we can just emit the regular loads.

See also #8765 that does a similar thing for RISC-V
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:riscv64 Issues related to the RISC-V 64 backend. 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.

2 participants