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

pulley: Add branch-with-compare-against-immediate #9863

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

alexcrichton
Copy link
Member

This commit adds a large number of new br_if_x* instructions which compare with an immediate instead of comparing two registers. This is pretty common in wasm/compiled code where, for example, loop upper bounds are often constants. This helps compress code slightly while fusing more instructions together.

The main cost of this is that the number of opcodes added here is quite large. Like with previous immediate-taking opcodes both 8 and 32-bit variants of immediates are added for all comparisons. Additionally unlike the previous set of branch-and-compare instructions it's required to add instructions for > and >= because the operands cannot be swapped to invert the condition, further increasing the number of opcodes added.

This is a mild size reduction on spidermonkey.cwasm from 29M to 28M but it's mostly expected to be a performance win for interpreted loops.

This commit adds a large number of new `br_if_x*` instructions which
compare with an immediate instead of comparing two registers. This is
pretty common in wasm/compiled code where, for example, loop upper
bounds are often constants. This helps compress code slightly while
fusing more instructions together.

The main cost of this is that the number of opcodes added here is quite
large. Like with previous immediate-taking opcodes both 8 and 32-bit
variants of immediates are added for all comparisons. Additionally
unlike the previous set of branch-and-compare instructions it's required
to add instructions for `>` and `>=` because the operands cannot be
swapped to invert the condition, further increasing the number of
opcodes added.

This is a mild size reduction on `spidermonkey.cwasm` from 29M to 28M
but it's mostly expected to be a performance win for interpreted loops.
@alexcrichton alexcrichton requested review from a team as code owners December 19, 2024 04:52
@alexcrichton alexcrichton requested review from fitzgen and removed request for a team December 19, 2024 04:52
@fitzgen fitzgen added this pull request to the merge queue Dec 19, 2024
Merged via the queue into bytecodealliance:main with commit 4178766 Dec 19, 2024
40 checks passed
@alexcrichton alexcrichton deleted the pulley-br-with-imm branch December 19, 2024 15:36
alexcrichton added a commit to alexcrichton/wasmtime that referenced this pull request Dec 19, 2024
This commit fixes a few mistakes that were introduced in bytecodealliance#9863.
Specifically when lowering `Cond.If...` and the arguments needed
swapping the condition was also inverted by accident. More `*.clif`
runtests were added to catch this case and expose it. Additionally
Pulley now has lowering for all the `FloatCC` orderings to be able to
run the `select.clif` runtest which primarily exposed the issue.
github-merge-queue bot pushed a commit that referenced this pull request Dec 20, 2024
This commit fixes a few mistakes that were introduced in #9863.
Specifically when lowering `Cond.If...` and the arguments needed
swapping the condition was also inverted by accident. More `*.clif`
runtests were added to catch this case and expose it. Additionally
Pulley now has lowering for all the `FloatCC` orderings to be able to
run the `select.clif` runtest which primarily exposed the issue.
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