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

Implement optimizations for i32.eqz translation. #795

Closed
Robbepop opened this issue Nov 23, 2023 · 2 comments
Closed

Implement optimizations for i32.eqz translation. #795

Robbepop opened this issue Nov 23, 2023 · 2 comments
Labels
optimization An performance optimization issue. register-machine A work item for the register-machine engine.

Comments

@Robbepop
Copy link
Member

Robbepop commented Nov 23, 2023

When translating a Wasm i32.eqz instruction we can view it as negation of local conditionals that can be in the form of i32.eq, i32.lt_s, i64.ge_u etc. and in some cases also i32.{and, or, xor}. Instead of simply emitting a wasmi IR i32.eq x imm(0) instruction we can sometimes instead negate the previous instruction thus emitting fewer instructions in total.

Although this optimization might be mitigated by Wasm codegens that already perform this optimization. More research is needed here.

Affected Wasm instructions if they come after an i32.eqz or i64.eqz:

  • br_if: Compile as br_if with negated conditional.
  • select: Compile as select with swapped operands. (equal to negated)

Affected Wasm instruction if they come before an i32.eqz or i64.eqz:

  • and, or: Compile as not-and or not-or. (to be further optimized by br_if)
  • Any Wasm comparison instruction such as i32.eq, i32.lt_s, i64.ge_u etc..
@Robbepop Robbepop added optimization An performance optimization issue. register-machine A work item for the register-machine engine. labels Nov 23, 2023
@Robbepop
Copy link
Member Author

The br_if enabled optimizations are going to be covered by #791.

@Robbepop
Copy link
Member Author

Generally this is just about i32.eqz + select after merging #791 which is a rather uncommon use case and not really important enough to introduce yet another bunch of new fused instructions. So we close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization An performance optimization issue. register-machine A work item for the register-machine engine.
Projects
None yet
Development

No branches or pull requests

1 participant