| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
|
|
|
|
| |
* remove-unused-brs: handle an if declared as returning a value despite having an unreachable condition
* simplify-locals: don't work on loops while the main pass is making changes, as set_locals are being tracked and modified.
|
| |
|
|
|
|
|
|
| |
* Use an if return value when one side is unreachable.
* Undo an if return value if we can use a br_if instead
|
|
|
|
|
| |
Add a version of simplify-locals which does not create nesting. This keeps the IR flat (in the sense of --flatten).
Also refactor simpify-locals to be a template, so the various modes are all template parameters.
|
| |
|
| |
|
|
|
|
| |
opts (#1523)
|
|
|
|
|
| |
The option keeps running the passes (that we were told to run) in cycles until we converge in terms of the binary size, that is, keep optimizing until we can't shrink any more.
Also fix a --metrics bug this uncovered: we can't expect the Metrics object to still be around if running passes later in another PassRunner.
|
| |
|
|
|
| |
Remove more of the unwanted stuff, and leave just an export to the function we are extracting. Then optimizations can do an effective cleanup.
|
|
|
| |
One pass may remove code that includes a tee which then makes more optimization possible. Found by the Souper investigations.
|
|
|
|
|
|
|
|
| |
Noticed by Souper.
* We only folded identical code in an if-else when both arms were blocks, so we were missing the case of one arm being just a singleton expression. This PR will wraps that in a block so the rest of the optimization can work on it, if it sees it is going to be folded out. Turns out this is common for phis.
* We only ran code-folding in -Os, because I assumed it was just good for code size, but as it may remove phis in the wasm VM later, seems like we should run it when not optimizing for size as well.
Together, these two shrink lua -O3 by almost 1%.
|
|
|
| |
Propagate constants through a tee_local. Found by Souper. Details in patch comments - basically we didn't differentiate precomputing a value and an expression.
|
|
|
|
|
|
| |
* Move more logic to the Literal class. We now leave all the work to there, except for handling traps.
* Avoid switching on the type, then the opcode, then Literal method usually switches on the type again - instead, do one big switch for the opcodes (then the Literal method is unchanged) which is shorter and clearer, and avoids that first switching.
|
|
|
|
|
| |
Report the offset with the error.
Also fix a compiler warning about comparing signed/unsigned types in the LEB code.
|
| |
|
|
|
| |
`xor` of 0, `and` and `or` of -1
|
|
|
|
|
| |
* Optimize shifts of 0.
* Optimize f(x, x) for various f (e.g., x & x => x).
|
|
|
|
|
|
|
|
|
| |
Stuff like x + 5 != 2 => x != -3.
Also some cleanups of utility functions I noticed while writing this, isTypeFloat => isFloatType.
Inspired by
https://github.com/golang/go/blob/master/src/cmd/compile/internal/ssa/gen/generic.rules
|
|
|
| |
Improve error handling, validation, and assertions for having a non-concrete type in an inappropriate place. Fixes a fuzz testcase.
|
|
|
|
|
|
|
|
|
|
| |
Inspired by #1501
* remove unneeded appearances of the default switch target (at the front or back of the list of targets)
* optimize a switch with 0, 1 or 2 targets into an if or if-chain
* optimize a br_if br pair when they have the same target
Makes e.g. fastcomp libc++ 2% smaller. Noticeable improvements on other things like box2d etc.
|
|
|
|
| |
makes loading large wasm files more than twice as fast (#1496)
|
|
|
|
|
| |
The optimization in #1495 had a bug which was found by the fuzzer: our binary format parsing will not emit unreachable code (it may be stacky, so we ignore it). However, while parsing it we note breaks that are taken there, and then we removed that code, leading to a state where a break was not taken in the code, but we thought it was.
This PR clarifies the difference between unreachable code in the wasm sense (anything from the start of a block til an unreachable is "reachable") and the literal sense (even that code at the start may not be literally reachable if the block is not reachable), and then we use literal unreachability to know what code will be ignored and therefore we should ignore breaks in.
|
|
|
|
| |
break to it - use that to avoid rescanning blocks for unreachability purposes (#1495)
|
|
|
|
|
|
|
|
|
|
|
|
| |
llvm-mirror/llvm@9273bb3([Phabricator](https://reviews.llvm.org/D44256))
changed alias assignment syntax from
```
x = y
```
to
```
.set x, y
```
This patch reflects the change.
|
|
|
|
| |
it by the standard calls, even if it was modified by user input (move it out of just being in wasm-reduce.cpp) (#1489)
|
| |
|
|
|
|
|
|
|
|
|
|
| |
When lowering i64 values in a function, we create new local variables
for all of the i64 local variables, one local for the low bits, and one
for the high bits. We create a mapping between the old locals and the
new as well. During translation, when we encountered a `get_local` that
didn't have type `i64`, we skipped it, on the supposition that there was
nothing to do. But that's not true; the local it was getting may have
been remapped to a new index in the lowered function, and we need to
account for that change. Similar logic holds for `set_local`.
|
|
|
|
|
|
|
| |
The documentation for the simplify-locals pass suggests running
reorder-locals after it to clean up unnecessary locals. wasm2asm wasn't
doing this, which meant that generated code had a number of unused
variables. A good minimizer will probably clean that up, but let's go
ahead and clean it up in wasm2asm itself.
|
|
|
|
|
| |
We were using the global to return 64-bit values from functions, but
said global wasn't actually present in the IR. This omission caused the
generated code to fail validation.
|
|
|
|
| |
unreachable, the modified version is as well (#1481)
|
| |
|
|
|
|
| |
found by valgrind (#1478)
|
|
|
|
|
|
|
|
|
| |
We were using Math_{min,max} in wasm2asm-generated files without
declaring said functions. This decision created problems for tests,
because Math_min (resp. max) would first be used on f32s, thus returning
f32, and then validation would fail when it was used on f64s.
The resulting changes make wasm2asm tests pass with MOZJS asm.js
validation, which moves #1443 forward.
|
|
|
|
|
|
| |
* After we see a function can't be removed, deprioritize trying to remove it again (it may just be unremovable).
* Focus on reducing segments exponentially first, before zeroing out what is left (which is not exponential).
This was helpful in reducing a massive sqlite testcase.
|
|
|
|
| |
and we assumed a non-get is a set (caught by valgrind) (#1472)
|
|
|
|
|
|
|
|
|
|
|
| |
This adds a pass that implements "function pointer cast emulation" - allows indirect calls to go through even if the number of arguments or their types is incorrect. That is undefined behavior in C/C++ but in practice somehow works in native archs. It is even relied upon in e.g. Python.
Emscripten already has such emulation for asm.js, which also worked for asm2wasm. This implements something like it in binaryen which also allows the wasm backend to use it. As a result, Python should now be portable using the wasm backend.
The mechanism used for the emulation is to make all indirect calls use a fixed number of arguments, all of type i64, and a return type of also i64. Thunks are then placed in the table which translate the arguments properly for the target, basically by reinterpreting to i64 and back. As a result, receiving an i64 when an i32 is sent will have the upper bits all zero, and the reverse would truncate the upper bits, etc. (Note that this is different than emscripten's existing emulation, which converts (as signed) to a double. That makes sense for JS where double's can contain all numeric values, but in wasm we have i64s. Also, bitwise conversion may be more like what native archs do anyhow. It is enough for Python.)
Also adds validation for a function's type matching the function's actual params and result (surprised we didn't have that before, but we didn't, and there was even a place in the test suite where that was wrong).
Also simplifies the build script by moving two cpp files into the wasm/ subdir, so they can be built once and shared between the various tools.
|
| |
|
|
|
|
|
|
| |
* limit the amount of asm2wasm warnings on arguments added/removed in flexible argument handling (e.g. in Python there can be many thousands of such warnings, flooding the output...)
* also lock, because those warnings can come from multiple threads
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* Emit invokeFuncs list as metadata
* Refactor s2wasm to use ModuleWriter
* Fix wasm-emscripten-finalize metadata output for binary output
* Add a flag to emit binary from s2wasm
NOTE: I chose to emit text by default, and binary behind a flag. This
mismatches with asm2wasm (and the expectations of users of a "2wasm"
tool), but doesn't break any existing users of s2wasm. If s2wasm is
deprecated in favor of lld, this will be the least disruptive change,
and we won't have to live with awkward defaults for too long.
* Emit source maps in the binary output of s2wasm
* Only emit binary with an outfile specified
|
|
|
|
| |
the checks (#1461)
|
|
|
|
|
|
|
|
|
|
| |
* replace assert with a proper trap for an invalid offset in table initialization
* fix offset handling in initial table size computation: it is an unsigned value
* handle traps in fuzz-exec when creating instance
* optimization may remove imports - and imported table init may trap, so opts may remove that trap. check for result comparisons in the right order, so we don't get bothered by that
|
| |
|
| |
|
|
|
|
| |
This change eliminates one issue that prevents asm.js validation of the
generated code, see #1443.
|
|
|
|
|
|
| |
* Drop start function in RemoveUnusedModuleElements if empty
* Update tests and dist files
|
| |
|
|
|
|
|
|
|
|
|
|
| |
* refactor BINARYEN_PASS_DEBUG code for writing byn-* files, make it easy to emit binaries instead of text
* fix up bad argument numbers in asm2wasm. This can be caused by undefined behavior on the LLVM side, which happens to work natively. it's nicer to fix it up like it would be in a native build, and give a warning, instead of failing to compile
* update build-js.sh
* updated builds
|
|
|
|
|
|
|
|
|
|
|
| |
* Emit EM_JS metadata
* Include s2wasm-style em_js support
* Change em_js metadata to be keyed on name
* Add testcase for em_js, don't always emit emJsFuncs metadata
* Better error handling for unexpectedly-formatted __em_js__ functions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* add tests for i32.popcnt
* lower i64.popcnt
* add tests for i64.extend_u/i32
* lower i64.extend_s/i32
* fix lowering i64.eqz
* lower i64.eqz more efficiently
* add tests for i32.clz/i32.ctz
* lower i64.clz/i64.ctz
|