-
Notifications
You must be signed in to change notification settings - Fork 740
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
Flush unused blocks. #32
Comments
Any example? Looking at the test outputs in |
From the zlib benchmark: Unnecessary block:
Unnecessary
This one could be eliminated:
Two unnecessary
Two unnecessary blocks:
|
Thanks for the details. Notes:
|
Note sure about your first point. Functions seem to accept a list of expressions so the top block seems unnecessary (or perhaps this is just a difference between v8 and the current spec)? Explored some clean up passes (but just hacks in lisp):
This seems to make the code a little more readable, and does reduce the compressed size. Also experimenting with |
Sorry if I wasn't clear. In the first point, I was saying that the binaryen AST is perhaps not identical to the spec. I discussed this in issues on the spec repo, and in the end it wasn't clear that there was a "best" way to represent the AST. For example, the binaryen Function doesn't directly have a list, instead they have a single child, which often is a block (which does have a list). That's why there are some of those blocks. I'm interested in those experiments. It should be fairly easy to do them in binaryen, at least I've tried to make it easy. Basically you can write a pass in |
I wrote RemoveUnusedNames, which removes the name of |
Thank you for making a start. There is a little more to it. Need to keep a stack of the block labels to be able to account for those in scope. Fwiw, here are the CL implementations:
|
I pushed several more commits that should address most of the points raised here. I'd appreciate it if you could take a look at the current output and see if anything looks easily optimizable. |
Thank you.
|
Updated Added the
The other passes can then clean this up to:
Practically only the elimination of the redundant trailing breaks seems useful on the asm2wasm output. Here's a real example. The
|
How did you test - perhaps you did not run the binaryen optimization passes? On your example (1), when I run
Then I get
Those three passes are run automatically after asm2wasm, so if you tested using that, it should also have worked. If it still doesn't work for you, can you provide the full input and command you are running, and not just the bad output? |
Thank you. Yes, I was not running it with all the passes. Looking again, there are still opportunities to flatten blocks within
There still remain some redundant |
It's not always safe to merge a named block into a parent unnamed block, since it moves the location of the branch target. I don't see enough in your first example to tell if that's the case there or not. For switch and case, I am not planning to optimize them yet since i think the spec might still change for them. But yes, that should eventually be optimized. |
It looks like this block was not flatten only because they are not optimized. Thank you. |
Seeing many unused
block
s, not just the$topmost
, produced via asm2wasm.The text was updated successfully, but these errors were encountered: