-
Notifications
You must be signed in to change notification settings - Fork 787
Superoptimizer #900
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
Superoptimizer #900
Conversation
…code it is shown, finding patters that it believe are valid optimizations, and suggesting them based on their importance/predicted impact
See |
I'm curious and would like to ask you a question, if you excuse my ignorance. |
Well, LLVM is just one thing that can produce wasm. Binaryen's optimizer should be able to optimize any wasm from any compiler, so having a superoptimizer here would benefit all those. Not many exist yet, of course, but hopefully they will. I also think it's convenient to superoptimize in Binaryen - the technique used here requires the ability to execute code, which is trivial in Binaryen (using the built-in interpreter), but not practical in LLVM. |
Ok, running the superoptimizer, it found a bunch of things missing in our optimizer, which I implemented in the 4 linked PRs (details in each one). The total benefits of those PRs:
Those PRs seem to cover most of what the superoptimizer finds for now - we'll need to improve it to find more, lots of TODOs in the superoptimizer source, it's really very naive so far. Nice that even with such a simple superoptimizer we can find useful improvements. As for this PR itself, for me personally it would be convenient to merge it, but possibly not worth it to increase build times for everyone, it could stay on this side branch. Thoughts? |
Let's close this, the optimizations from this are helpful, but probably not much sense in getting the superoptimizer itself in-tree. It can stay in a side branch. |
I'm doing more experiments here, and restoring/updating this branch. |
Amazing! I expect it would be very helpful to run this on SIMD programs. In particular, if we could randomly generate vectorized LLVM programs, run them through the Wasm backend, then run them through the Binaryen superoptimizer to see what we missed in ISel, I think that would help use make significant improvements in LLVM. |
Ah, interesting, I hadn't thought about SIMD... makes sense it could help. I think the code will need some changes for v128 but hopefully not many. My motivation was mainly wasm GC, where more toolchains are not using LLVM. The old superoptimizer results were only on LLVM output, so there might be more or different opportunities now. Side note, I reopened this branch, but I do not have the power to reopen this PR... and new commits I've pushed are not showing up.. 🤷 I guess I'll open a new PR with the updated code. |
This adds a
wasm-analyze
tool that looks at a set of input files and runs a superoptimizer to find possible optimizations to suggest should be written. The general idea is based on Bansal & Aiken (2006), "Automatic Generation of Peephole Superoptimizers". In more detail:So far this is not much tuned, but already suggests a few new optimizations worth adding. I haven't gotten to that yet.