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

Optimize stack-encoded instructions after emission #40

Open
alexcrichton opened this issue Feb 1, 2019 · 2 comments
Open

Optimize stack-encoded instructions after emission #40

alexcrichton opened this issue Feb 1, 2019 · 2 comments

Comments

@alexcrichton
Copy link
Collaborator

Currently we encode functions to raw wasm and the we're done. Due to our representation with a tree-like AST, however, there are possible optimizations in the encoded instructions we can't necessarily represent in the AST. For example:

call $foo
drop
i32.const 1
return

can be more efficiently encoded as:

call $foo
i32.const 1
return

Or similarly whatever AST we settle on for:

i32.const 1
i32.const 1
call $foo ;; no inputs or outputs
i32.xor

can be optimally represented as above, but the AST is likely to look more like:

(i32.xor
  (i32.const 1)
  (block (result i32)
    (call $foo)
    (i32.const 1)))
@fitzgen
Copy link
Member

fitzgen commented Feb 1, 2019

can be optimally represented as above, but the AST is likely to look more like:

(i32.xor
  (i32.const 1)
  (block (result i32)
    (call $foo)
    (i32.const 1)))

I think this will take us pretty far, especially assuming wasm-opt follows us (for production builds at least)

@alexcrichton
Copy link
Collaborator Author

Oh actually that was an incorrect AST, it'd actually have to be:

call $a
call $a
call $b
i32.xor

transforms to:

(local i32)
(i32.xor 
  (call $a)
  (block (result i32)
    (local.set 0 (call $a))
    (call $b)
    (local.get 0)))

(can't reorder call $a and call $b!)

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

No branches or pull requests

2 participants