summaryrefslogtreecommitdiff
path: root/test/wasm2js
Commit message (Collapse)AuthorAgeFilesLines
* OptimizeInstructions: Move identical unary code out of if/select arms (#3828)Alon Zakai2021-04-212-4/+4
| | | | | | | | | | | | | | | | | | | | | (select (foo (X) ) (foo (Y) ) (condition) ) => (foo (select (X) (Y) (condition) ) ) To make this simpler, refactor optimizeTernary to be templated.
* Remove passive keyword from data segment parser (#3757)Abbas Mashayekh2021-03-301-2/+2
| | | | | | | | The passive keyword has been removed from spec's text format, and now any data segment that doesn't have an offset is considered as passive. This PR remove that from both parser and the Print pass, plus all tests that used that syntax. Fixes #2339
* Inlining: Always inline single-use functions (#3730)Alon Zakai2021-03-299-303/+213
| | | | | | | | | | | | | | | | This implements emscripten-core/emscripten#13744 Inlining functions with a single use allows us to remove the function afterward. That looks highly beneficial, shrinking every single benchmark in emscripten's benchmark suite, by an average of 2% on the macrobenchmarks and 3.5% on all of them. Speed also improves, although mostly on the microbenchmarks so that might be less realistic. There may be a slight downside to startup time due to emitting larger functions, but given the baseline compilers in VMs these days it seems worth it, as the delay would be just to get to the upper tier. On the benchmark suite the risk seems low. See more details in the PR above.
* Add a test for memory.size in wasm2js (#3547)Alon Zakai2021-02-043-2/+13
| | | Support has been there all along, but we didn't have a reference test of it.
* Rename atomic.notify and *.atomic.wait (#3353)Heejin Ahn2020-11-131-3/+3
| | | | | | | | | | | | | | - atomic.notify -> memory.atomic.notify - i32.atomic.wait -> memory.atomic.wait32 - i64.atomic.wait -> memory.atomic.wait64 See WebAssembly/threads#149. This renames instruction name printing but not the internal data structure names, such as `AtomicNotify`, which are not always the same as printed instruction names anyway. This also does not modify C API. But this fixes interface functions in binaryen.js because it seems binaryen.js's interface functions all follow the corresponding instruction names.
* wasm2js: Declare data segments before calling asmFunc (#3337)Sam Clegg2020-11-1129-380/+383
| | | | | | | | | This is because we maybe need to reference the segments during the start function. For example in the case of pthreads we conditionally load passive segments during start. Tested in emscripten with: tests/runner.py wasm2js1
* wasm2js: Support for exported memory (#3323)Sam Clegg2020-11-1029-206/+197
| | | | | The asmFunc now sets the outer scope's `bufferView` variable as well as its own internal views.
* [wasm2js] Use native JavaScript Math.trunc (#3329)Max Graey2020-11-10113-18/+148
|
* Canonicalize subtraction with constant on the right to addition (#3321)Max Graey2020-11-1014-20/+20
| | | | | | | Using addition in more places is better for gzip, and helps simplify the optimizer as well. Add a FinalOptimizer phase to do optimizations like our signed LEB tweaks, to reduce binary size in the rare case when we do want a subtraction.
* wasm2js: Remove global dict arguments to asmFunc (#3325)Sam Clegg2020-11-05113-4233/+2336
|
* MemoryPacking: Properly notice zeroFilledMemory (#3306)Alon Zakai2020-11-023-7/+3
| | | We can only pack memory if we know it is zero-filled before us.
* RemoveUnusedBrs: Properly check for effects in selectify() (#3310)Alon Zakai2020-11-013-33/+23
| | | | | Selectify turns an if-else into a select where possible. Previously we abandoned hope if any part of the if had a side effect. But it's fine for the condition to have a side effect, so long as moving it to the end doesn't invalidate the arms.
* Canonicalize relationals as well (#3303)Max Graey2020-10-306-14/+14
|
* Rewrite DCE pass (#3274)Alon Zakai2020-10-264-49/+69
| | | | | | | | | | | | | | | | | | | | | | | | | The DCE pass is one of the oldest in binaryen, and had quite a lot of cruft from the changes in unreachability and other stuff in wasm and binaryen's history. This PR rewrites it from scratch, making it about 1/3 the size. I noticed this when looking for places to use code autogeneration. The old version had annoying boilerplate, while the new one avoids any need for it. There may be noticeable differences, as the old pass did more than it needed to. It overlapped with remove-unused-names for some reason I don't remember. The new pass leaves that to the other pass to do. I added another run of remove-unused-names to avoid noticeable differences in optimized builds, but you can see differences in the testcases that only run DCE by itself. (The test differences in this PR are mostly whitespace.) (The overlap is that if a block ended up not needed, that is, all branches to it were removed, the old DCE would remove the block.) This pass is about 15% faster than the old version. However, when adding another run of remove-unused-names the difference basically vanishes, so this isn't a speedup.
* Optimize relations of subtractions and zero (#3275)Max Graey2020-10-251-3/+3
|
* Optimize power of two float divisions (#3018)Max Graey2020-10-132-4/+4
|
* wasm2js: override incoming memory's grow method (#3185)Sam Clegg2020-09-3012-36/+46
| | | | | | | | | | This will allow for the completely removal of `__growWasmMemory` as a followup. We currently unconditionally generate this function in `generateMemoryGrowthFunction`. See #3180
* Remove unnecessary "new" on Table generation in wasm2js (#3163)Alon Zakai2020-09-302-2/+2
| | | It's not an actual constructor, just a JS function that returns the object.
* wasm2js: Skip heap creation in the absence of wasm memory. NFC (#3167)Sam Clegg2020-09-24107-1239/+2296
| | | | | Also, format the asmFunc call to make it more readable in the ES6 modules case.
* Remove stale test output (#3157)Sam Clegg2020-09-2113-10225/+0
| | | | | | | | | | | | These test output files are ignored and so contain stale output that is neither checked during `check.py` not updated during `auto_update_tests.py`. There are three clases to tests here: 1. Spec tests that end in 64.wast are ignored by scripts/test/wasm2js.py 2. Spec tests that are globallyi ignoed by shared.py:SPEC_TESTS_TO_SKIP 3. hello_world.2asm.js.. I cant tell where this came remove it seems like an anomaly.
* wasm2js: Support exported tables (#3152)Sam Clegg2020-09-21110-158/+48
|
* Add float operations for isSymmetric util (#3127)Max Graey2020-09-142-8/+8
| | | Add floating point Eq and Ne operators to Properties::isSymmetric. Also treat additional float ops as symmetric specifically in OptimizeInstructions when their operands are known to be non-NaN.
* Fix wasm2js memory import in case it is minified (#3113)Alon Zakai2020-09-103-0/+134
| | | | | | | | | | | | | | | It was hardcoded as "env.memory", which is usually correct. But if we minify import names, as in -O3 in emscripten, we need to use the minified name. Note how in the test it now emits var memory = env.a; for the import. Fixes emscripten-core/emscripten#12123 This was not noticed earlier since that import is only used in memory growth. The tests that would catch it are wasm2js3.test*memory_growth* but we only run wasm2js1 on CI. I'll add testing after this lands.
* wasm2js: Add an "Export" scope for name resolution (#2998)Alon Zakai2020-07-302-34/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously we used "Top" for both exports and the top level (which has functions and globals). The warning about name collisions there was meant only for exports (where if a name collides and so it must be renamed, means that there will be an externally-visible oddness for the user). But it applied to functions too, which could be annoying, and was not dangerous (at worst, it might be confusing when reading the emitted JS and seeing NAME_1, NAME_2, but there is no effect on execution or on exports). To fix this, add a new Export name scope. This separates function names from export names. However, it runs into another issue which is that when checking for a name conflict we had a big set of all the names in all the scopes. That is, FOO would only ever be used in one scope, period, and other appearances of that Name in wasm would get a suffix. As a result, if an exported function FOO has the name foo, we'd export it as FOO but name the function FOO_1 which is annoying. To fix that, keep sets of all names in each scope. When mangling a name we can then only care about the relevant scope, EXCEPT for local names, which must also not conflict with function names. That is, this would be bad: function foo(bar) { var bar = 0; } function bar() { .. It's not ok to call a parameter "bar" if there is a function by that name (well, it could be if it isn't called in that scope). So when mangling the Local scope, also check the Top one as well. The test output changes are due to non-overlapping scopes, specifically Local and Label. It's fine to have foo : while(1) { var foo = 5; } Those "foo"s do not conflict. Fixes emscripten-core/emscripten#11743
* wasm2js: Remove an incorrect optimization (#3004)Alon Zakai2020-07-291-2/+2
| | | | optimizeBoolean does not receive a boolean, it is done when the output flows into a boolean context.
* wasm2js: Don't remove an | 0 or >>> 0 in a boolean context (#2993)Alon Zakai2020-07-282-8/+8
| | | | | | | | | | | | | It is usually fine to do if (x | 0) => if (x) since it just cares if the value is 0 or not. However, if the cast turns it into 0, then that is incorrect, which the fuzzer found as -2147483648 + -2147483648 | 0 (the sum is 2^32, which | 0 is 0). We can maybe look into doing this in a safe way, but for now just remove it. It doesn't have a big impact on code size as this is pretty rare (e.g. the minimal runtime code size test is not broken by this).
* wasm2js: coerce function pointer indexes (#2979)Alon Zakai2020-07-229-14/+122
| | | | | | | | | | | | | | | | | We emit FUNCTION_TABLE[ptr], where FUNCTION_TABLE is a JS array. That is a rare case where true is handled differently than 1 (a typed array or an add would cast, etc.), so we must explicitly cast there. Fixes an issue that existed before, but became a problem due to #2869 which optimized some selects into a form that emitted a true or a false, and if that was a function pointer, it could be bad, see https://app.circleci.com/pipelines/github/emscripten-core/emscripten/6699/workflows/0c4da49c-75d0-4b0a-8fac-686a8330a3fe/jobs/336520 The new test/wasm2js/indirect-select.2asm.js.opt output shows what happened there. Verified as passing emscripten's wasm2js1 wasm2js2 test suites.
* Optimize select with const arms (#2869)Max Graey2020-07-222-53/+21
| | | | | x ? 1 : 0 => !!x and so forth.
* wasm2js: Fix a bug with adjacent reinterprets (#2964)Alon Zakai2020-07-2018-80/+220
| | | | | | | | | | | i64 reinterprets were lowered in the i64 pass, and i32s at the very end, in wasm2js itself. This could break since in between the i64 pass and wasm2js we run optimizations, and the optimizer was not aware of what we lower the i32 reinterprets to - calls to use scratch memory. Those calls have a side effect of altering scratch memory. The optimizer just saw an i32 reinterpret, and moved it across the i64 reinterpret's scratch memory calls. This makes 32-bit reinterprets use separate scratch memory from 64-bit ones, which means they can never interfere with each other.
* wasm2js: Sign-extend support (#2949)Alon Zakai2020-07-103-0/+94
| | | | | | The usual "trick" to extend: shift left so the sign bit in the small integer is now the sign bit in a 32-bit integer, then shift right to spread that sign bit out and return the lower bits to their proper place, (x << 24) >> 24.
* Wasm2js Atomics support (#2924)Alon Zakai2020-06-233-0/+339
| | | | | Atomic loads, stores, RMW, cmpXchg, wait, and notify. This is enough to get the asm.js atomics tests in the emscripten test suite to pass, at least (but they are a subset of the entire pthreads suite).
* wasm2js: Avoid 64-bit scratch memory helpers in wasm-intrinsics (#2926)Alon Zakai2020-06-234-980/+292
| | | | | | | | | | | | | | That code originally used memory location 1024 to save 64 bits of data (as that is what rust does apparently). We refactored it manually to instead use a scratch memory helper, which is safer. However, that 64-bit function ends up legalized, which actually changes the interface between the module and the outside, which is confusing and causes problems with optimizations that can remove the getTempRet0 imports, see emscripten-core/emscripten#11456 Instead, just use a global i64 to stash those bits. This requires adding support for copying globals from the intrinsics module, but otherwise seems simpler overall.
* Fix breakage on master from colliding landings (#2927)Alon Zakai2020-06-232-0/+2
|
* wasm2js: start function support (#2920)Alon Zakai2020-06-223-0/+129
|
* More optimizations for pow of two and pos/neg one const on the right (#2870)Max Graey2020-06-222-2/+2
|
* wasm2js: Bulk memory support (#2923)Alon Zakai2020-06-2221-16/+830
| | | | | | | | | | | | | | Adds a special helper functions for data.drop etc., as unlike most wasm instructions these are too big to emit inline. Track passive segments at runtime in var memorySegments whose indexes are the segment indexes. Emit var bufferView even if the memory exists even without memory segments, as we do still need the view in order to operate on it. Also adds a few constants for atomics that will be useful in future PRs (as this PR updates the constant lists anyhow).
* Micro-optimize base64Decode (#2897)juj2020-06-068-56/+40
| | | | | * Micro-optimize base64Decode * Update test expectations
* Add --deterministic flag to wasm2js, for fuzzing (#2757)Alon Zakai2020-04-133-0/+101
| | | | | | | | | | | | | | | | | | | | | | In wasm2js we ignore things that trap in wasm that we can't really handle, like a load from memory out of bounds would trap in wasm, but in JS we don't want to emit a bounds check on each load. So wasm2js focuses on programs that don't trap. However, this is annoying in the fuzzer as it turns out that our behavior for places where wasm would trap was not deterministic. That is, wasm would trap, wasm2js would not trap and do behavior X, and wasm2js with optimizations would also not trap but do behavior Y != X. This produced false positives in the fuzzer (and might be annoying in manual debugging too). As a workaround, this adds a --deterministic flag to wasm2js, which tries to be deterministic about what it does for cases where wasm would trap. This handles the case of an int division by 0 which traps in wasm but without this flag could have different behavior in wasm2js with or without opts (see details in the patch).
* Remove writes to globals that are never written to (#2741)Sam Clegg2020-04-091-4/+1
| | | | | Since the global is never read, we know that any write operation will be unobservable.
* Fix missing newline after // EMSCRIPTEN_START_FUNCS and // ↵juj2020-02-106-12/+24
| | | | | | | | | | EMSCRIPTEN_END_FUNCS markers. (#2626) * Fix missing newline after // EMSCRIPTEN_START_FUNCS and // EMSCRIPTEN_END_FUNCS markers. * Flake * Update tests
* Optimize base64 decoding (#2623)juj2020-02-098-150/+182
| | | | | | | | | | | | | | * Optimize base64 decoding (about 7x-10x faster and temporary garbage-free compared to the original version) * new Uint8Array * Reuse Uint8Array view * Fix end handling * Code format * Update tests
* Optimize passive segments in memory-packing (#2426)Thomas Lively2020-01-151-4/+2
| | | | | | | | | When memory is packed and there are passive segments, bulk memory operations that reference those segments by index need to be updated to reflect the new indices and possibly split into multiple instructions that reference multiple split segments. For some bulk-memory operations, it is necessary to introduce new globals to explicitly track the drop state of the original segments, but this PR is careful to only add globals where necessary.
* wasm2js: Do not convert x >>> 0 | 0 to x >>> 0 (#2581)Alon Zakai2020-01-104-18/+18
| | | | | | | | | | | | isBinary was used where we should only accept a signed binary, as removing the | 0 from an unsigned value may be incorrect. This does regress a few small things (as can be seen in the diff). If it's important we can add more sophisticated optimizations here, perhaps like an assumption that the signedness of a local never matters. Fixes emscripten-core/emscripten#10173
* DCE at the end of wasm2js (#2574)Alon Zakai2020-01-067-69/+262
| | | | | | By doing so we ensure that our calls to convert wasm types to JS types never try to convert an unreachable. Fixes #2558
* Update spec test suite (#2484)Heejin Ahn2019-11-2912-784/+4629
| | | | | | | | | | | | | This updates spec test suite to that of the current up-to-date version of https://github.com/WebAssembly/spec repo. - All failing tests are added in `BLACKLIST` in shared.py with reasons. - For tests that already existed and was passing and started failing after the update, we add the new test to the blacklist and preserve the old file by renaming it to 'old_[FILENAME].wast' not to lose test coverage. When the cause of the error is fixed or the unsupported construct gets support so the new test passes, we can delete the corresponding 'old_[FILENAME].wast' file. - Adds support for `spectest.print_[type] style imports.
* SimplifyGlobals: Apply known constant values in linear traces (#2340)Alon Zakai2019-09-131-1/+1
| | | | | | | | | | | | | This optimizes stuff like (global.set $x (i32.const 123)) (global.get $x) into (global.set $x (i32.const 123)) (i32.const 123) This doesn't help much with LLVM output as it's rare to use globals (except for the stack pointer, and that's already well optimized), but it may help on general wasm. It can also help with Asyncify that does use globals extensively.
* [wasm2js] Fix memory.size (#2330)Alon Zakai2019-09-0518-40/+72
| | | | | | | We emitted the __wasm_memory_size function only when memory growth was enabled, but it can be used without that too. In theory we could only emit it if either memory growth or memory.size is used, but I think we can expect JS minifiers to do that later. Also fix a test suite bug - the check/auto_update script didn't run all the wasm2js tests when you run it with argument wasm2js (it used that as the list of tests, instead of the list of files, which confused me here for a while...).
* Followup to workaround for minification of wasm2js mem init (#2318)Brion Vibber2019-08-309-27/+27
| | | | | | | | | | | | | Emscripten's minifier mis-minifies a couple bits in the memory init function that's used with wasm2js when not using an external memory init file: https://github.com/emscripten-core/emscripten/issues/8886 Previous fix worked around the bug in one place but failed to account for another. Have now confirmed that it works with this change in place. Updated test cases to match.
* Allow all features on wasm2js and add atomic tests (#2311)Heejin Ahn2019-08-283-0/+102
| | | | | | This adds `-all` argument to wasm2js testing and fixes wasm2js to actually take that argument (currently it doesn't, when it takes a wast file). This also adds a wasm2js test for `atomic.fence` instruction that was added in #2307.
* Do not hoist truncation of wasm2js divisions (#2305)Thomas Lively2019-08-263-0/+87
| | | | | | It is not valid to defer the truncation of divisions because accumulated non-integral results can produce different values when they are combined before truncation. This was causing a test failure in the Rust test suite.