summaryrefslogtreecommitdiff
path: root/test
Commit message (Collapse)AuthorAgeFilesLines
...
* Rename atomic.notify and *.atomic.wait (#3353)Heejin Ahn2020-11-1327-92/+92
| | | | | | | | | | | | | | - 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.
* Fix a hashing regression from #3332 (#3349)Alon Zakai2020-11-133-0/+27
| | | | | | | | | | | | | | | We used to check if a load's sign matters before hashing it. If the load does not extend, then the sign doesn't matter, and we ignored the value there. It turns out that value could be garbage, as we didn't assign it in the binary reader, if it wasn't relevant. In the rewrite this was missed, and actually it's not really possible to do, since we have just a macro for the field, but not the object it is on - which there may be more than one. To fix this, just always assign the field. This is simpler anyhow, and avoids confusion not just here but probably when debugging. The testcase here is reduced from the fuzzer, and is not a 100% guarantee to catch a read of uninitialized memory, but it can't hurt, and with ASan it may be pretty consistent.
* Update tests following conflicting landings (#3345)Alon Zakai2020-11-121-1/+1
|
* Module splitting (#3317)Thomas Lively2020-11-122-0/+930
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Adds the capability to programatically split a module into a primary and secondary module such that the primary module can be compiled and run before the secondary module has been instantiated. All calls to secondary functions (i.e. functions that have been split out into the secondary module) in the primary module are rewritten to be indirect calls through the table. Initially, the table slots of all secondary functions contain references to imported placeholder functions. When the secondary module is instantiated, it will automatically patch the table to insert references to the original functions. The process of module splitting involves these steps: 1. Create the new secondary module. 2. Export globals, events, tables, and memories from the primary module and import them in the secondary module. 3. Move the deferred functions from the primary to the secondary module. 4. For any secondary function exported from the primary module, export in its place a trampoline function that makes an indirect call to its placeholder function (and eventually to the original secondary function), allocating a new table slot for the placeholder if necessary. 5. Rewrite direct calls from primary functions to secondary functions to be indirect calls to their placeholder functions (and eventually to their original secondary functions), allocating new table slots for the placeholders if necessary. 6. For each primary function directly called from a secondary function, export the primary function if it is not already exported and import it into the secondary module. 7. Replace all references to secondary functions in the primary module's table segments with references to imported placeholder functions. 8. Create new active table segments in the secondary module that will replace all the placeholder function references in the table with references to their corresponding secondary functions upon instantiation. Functions can be used or referenced three ways in a WebAssembly module: they can be exported, called, or placed in a table. The above procedure introduces a layer of indirection to each of those mechanisms that removes all references to secondary functions from the primary module but restores the original program's semantics once the secondary module is instantiated. As more mechanisms that reference functions are added in the future, such as ref.func instructions, they will have to be modified to use a similar layer of indirection. The code as currently written makes a few assumptions about the module that is being split: 1. It assumes that mutable-globals is allowed. This could be worked around by introducing wrapper functions for globals and rewriting secondary code that accesses them, but now that mutable-globals is shipped on all browsers, hopefully that extra complexity won't be necessary. 2. It assumes that all table segment offsets are constants. This simplifies the generation of segments to actively patch in the secondary functions without overwriting any other table slots. This assumption could be relaxed by 1) having secondary segments re-write primary function slots as well, 2) allowing addition in segment offsets, or 3) synthesizing a start function to modify the table instead of using segments. 3. It assumes that each function appears in the table at most once. This isn't necessarily true in general or even for LLVM output after function deduplication. Relaxing this assumption would just require slightly more complex code, so it is a good candidate for a follow up PR. Future Binaryen work for this feature includes providing a command line tool exposing this functionality as well as C API, JS API, and fuzzer support. We will also want to provide a simple instrumentation pass for finding dead or late-executing functions that would be good candidates for splitting out. It would also be good to integrate that instrumentation with future function outlining work so that dead or exceptional basic blocks could be split out into a separate module.
* [Fuzzer] Add a chance to pick particularly important initial contents (#3343)Alon Zakai2020-11-122-246/+279
| | | | | | | | | | | | OptimizeInstructions is seeing the most work these days, so it's good for the fuzzer to focus on that some more. Also move some code around in the main test wast: it's useful to put each feature in its own module to maximize the chance of getting them to be used. That is, if a module has a single use of atomics, then if atomics are disabled in the current run, we can't use any of the module and we skip initial contents entirely. Moving each feature to it's own module reduces that risk. (We do pick randomly between the modules, and atm a small module has the same chance as a big one, but this still seems worth it.)
* Some refactorings in addition to #3338 (#3336)Max Graey2020-11-122-0/+104
| | | | See discussion in #3303
* OptimizeInstructions: Fix regression from #3303 / #3275 (#3338)Alon Zakai2020-11-123-9/+102
| | | | | | | | | | | | | | | | | X - Y <= 0 => X <= Y That is true mathematically, but not in the case of an overflow, e.g. X=10, Y=0x8000000000000000. X - Y is a negative number, so X - Y <= 0 is true. But it is not true that X <= Y (as Y is negative, but X is not). See discussion in #3303 (comment) The actual regression was in #3275, but the fuzzer had an easier time finding it due to #3303
* Fix BinaryenFunctionOptimize. (#3339)Alon Zakai2020-11-112-0/+43
| | | | | | We mistakenly tried to run all passes there, but should run only the function ones. Fixes #3333
* 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
* Avoid boilerplate in ExpressionAnalyzer comparing & hashing (#3332)Alon Zakai2020-11-112-0/+143
| | | | | | | | | | | | | | | | | | | | Expands on #3294: * Scope names must be distinguished as either defs or uses. * Error when a core #define is missing, which is less error-prone, as suggested by @tlively * Add DELEGATE_GET_FIELD which lets one define "get the field" once and then all the loops can use it. This helps avoid boilerplate for loops at least in some cases (when there is a single object on which to get the field). With those, it is possible to replace boilerplate in comparisons and hashing logic. This also fixes a bug where BrOnExn::sent was not scanned there. Add some unit tests for hashing. We didn't have any, and hashing can be subtly wrong without observable external effects (just more collisions).
* 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.
* Optimize i32(x) % C_pot in boolean context (#3307)Max Graey2020-11-102-0/+38
| | | | | | bool(i32(x) % C_pot) -> bool(i32(x) & (C_pot - 1)) bool(i32(x) % min_s) -> bool(i32(x) & max_s) For all other situations we already do this for (i32|i64).rem_s
* [wasm2js] Use native JavaScript Math.trunc (#3329)Max Graey2020-11-10117-48/+153
|
* Canonicalize subtraction with constant on the right to addition (#3321)Max Graey2020-11-1023-217/+217
| | | | | | | 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.
* Remove dead code and unused includes. NFC. (#3328)Sam Clegg2020-11-081-7/+7
| | | Specifically try to cleanup use of asm_v_wasm.h and asmjs constants.
* Remove OptimizeCalls from PostEmscripten. NFC. (#3326)Sam Clegg2020-11-062-149/+12
| | | We no longer build modules that import `global.Math`.
* wasm2js: Remove global dict arguments to asmFunc (#3325)Sam Clegg2020-11-05116-4311/+2375
|
* Optimize signed / unsigned relationals when RHS is min or max constant (#3314)Max Graey2020-11-044-21/+286
|
* More precise implicitTrap detection for binary extressions (#3312)Max Graey2020-11-043-14/+12
| | | | | | | Division and remainder do not have an implicit trap if the right-hand side is a constant and not one of the dangerous values there. Also refactor ignoreImplicitTrap handling for clarity.
* Optimize x * -1.0 in non-fastMath case (#3315)Max Graey2020-11-031-10/+10
| | | | | | | | | | | | | | We can still make x * -1.0 cheaper for non-fastMath mode as: x * -1.0 -> -0.0 - x Should at least help baseline compilers. Also it could enable further optimizations, e.g.: a + b * -1 a + (-0.0 - b) (a - 0.0) - b a - b
* MemoryPacking: Properly notice zeroFilledMemory (#3306)Alon Zakai2020-11-029-34/+61
| | | 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-018-67/+200
| | | | | 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.
* Improve CostAnalyzer (#3309)Max Graey2020-10-312-5/+6
| | | | | | | Make select cost more realistic - it should be as good as a jmp, as in an if. Add missing child visiting. Shorten repetitive cases in switches.
* Canonicalize relationals as well (#3303)Max Graey2020-10-3012-83/+161
|
* Standardize NaNs in the interpreter, when there is nondeterminism (#3298)Alon Zakai2020-10-306-63/+521
| | | | | | | Specifically, pick a simple positive canonical NaN as the NaN output, when the output is a NaN. This is the same as what tools like wabt do. This fixes a testcase found by the fuzzer on #3289 but it was not that PR's fault.
* [Memory64] (#3302)Wouter van Oortmerssen2020-10-302-6/+8
| | | Fixed bug in memory64-lowering pass for memory.size/grow
* Fold subtraction of sums or differences from constants (#3295)Max Graey2020-10-292-0/+99
| | | | | `C1 - (x + C2)` -> `(C1 - C2) - x` `C1 - (x - C2)` -> `(C1 + C2) - x` `C1 - (C2 - x)` -> `x + (C1 - C2)`
* Inlining fix: Note the start function (#3301)Alon Zakai2020-10-292-0/+23
| | | | Without this, we might think a function has no global uses if the only global use of it is the start.
* wasm-emscripten-finalize: Remove staticBump from metadata (#3300)Sam Clegg2020-10-2943-188/+110
| | | | | | Emscripten no longer needs this information as of https://github.com/emscripten-core/emscripten/pull/12643. This also removes the need to export __data_end.
* Optimize negative one on LHS for some shift operations (#3292)Max Graey2020-10-292-0/+71
|
* Use RAII in fuzzer for function context creation (#3296)Alon Zakai2020-10-291-585/+505
| | | Followup to #3276
* Remove support for emscripten legacy PIC ABI (#3299)Sam Clegg2020-10-2910-229/+76
|
* Fix pow2 util and avoid pow2 for left shifting in ZeroRemover (#3293)Max Graey2020-10-282-1/+25
| | | | | | | | Fixes a fuzz bug that was triggered by https://github.com/WebAssembly/binaryen/pull/3015#issuecomment-718001620 but was actually a pre-existing bug in pow2, that that PR just happened to uncover.
* Prototype new SIMD multiplications (#3291)Thomas Lively2020-10-285-92/+406
| | | | | | | Including saturating, rounding Q15 multiplication as proposed in https://github.com/WebAssembly/simd/pull/365 and extending multiplications as proposed in https://github.com/WebAssembly/simd/pull/376. Since these are just prototypes, skips adding them to the C or JS APIs and the fuzzer, as well as implementing them in the interpreter.
* Propagate sign to constants for float point expressions (#3289)Max Graey2020-10-273-19/+103
|
* Replace x * 2 with x + x for floats (#3016)Max Graey2020-10-272-0/+48
| | | But only when doing so doesn't require adding a new local.
* DWARF: Fix handling of the end of control flow instructions (#3288)Alon Zakai2020-10-273-178/+166
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously when we processed a block for example, we'd do this: ;; start is here (block (result type) ;; end is here .. contents .. ) ;; end delimiter is here Not how this represents the block's start and end as the "header", and uses an extra delimiter to mark the end. I think this is wrong, and was an attempt to handle some offsets from LLVM that otherwise made no sense, ones at the end of the "header". But it turns out that this makes us completely incorrect on some things where there is a low/high pc pair, and we need to understand that the end of a block is at the end opcode at the very end, and not the end of the header. This PR changes us to do that, i.e. ;; start is here (block (result type) .. contents .. ) ;; end is here This fixes a testcase already in the test suite, test/passes/fib_nonzero-low-pc_dwarf.bin.txt where you can see that lexical block now has a valid value for the end, and not a 0 (the proper scope extends all the way to the end of the big block in that function, and is now the same in the DWARF before and after we process it). test/passes/fannkuch3_dwarf.bin.txt is also improved by this. To implement this, this removes the BinaryLocations::End delimeter. After this we just need one type of delimiter actually, but I didn't refactor that any more to keep this PR small (see TODO). This removes an assertion in writeDebugLocationEnd() that is no longer valid: the assert ensures that we wrote an end only if there was a 0 for the end, but for a control flow structure, we write the end of the "header" automatically like for any expression, and then overwrite it later when we finish writing the children and the end marker. We could in theory special-case control flow structures to avoid the first write, but it would add more complexity. This uncovered what appears to be a possible bug in our debug_line handling, see test/passes/fannkuch3_manyopts_dwarf.bin.txt. That needs to be looked into more, but I suspect that was invalid info from when we looked at the end of the "header" of control flow structures. Note that there was one definite bug uncovered here, fixed by the extra } else if (locationUpdater.hasOldExprEnd(oldAddr)) { that is added here, which was definitely a bug.
* Fuzzer: Add an option to fuzz with initial wasm contents (#3276)Alon Zakai2020-10-275-743/+894
| | | | | | | | | | | | | | | | | | | | | | | | | Previously the fuzzer constructed a new random valid wasm file from scratch. The new --initial-fuzz=FILENAME option makes it start from an existing wasm file, and then add random contents on top of that. It also randomly modifies the existing contents, for example tweaking a Const, replacing some nodes with other things of the same type, etc. It also has a chance to replace a drop with a logging (as some of our tests just drop a result, and we match the optimized output's wasm instead of the result; by logging, the fuzzer can check things). The goal is to find bugs by using existing hand-written testcases as a basis. This PR uses the test suite's testcases as initial fuzz contents. This can find issues as they often check for corner cases - they are designed to be "interesting", which random data may be less likely to find. This has found several bugs already, see recent fuzz fixes. I mentioned the first few on Twitter but past 4 I stopped counting... https://twitter.com/kripken/status/1314323318036602880 This required various changes to the fuzzer's generation to account for the fact that there can be existing functions and so forth before it starts to run, so it needs to avoid collisions and so forth.
* Implement i8x16.popcnt (#3286)Thomas Lively2020-10-277-155/+171
| | | | | | As proposed in https://github.com/WebAssembly/simd/pull/379. Since this instruction is still being evaluated for inclusion in the SIMD proposal, this PR does not add support for it to the C/JS APIs or to the fuzzer. This PR also performs a drive-by fix for unrelated instructions in c-api-kitchen-sink.c
* Rewrite DCE pass (#3274)Alon Zakai2020-10-2616-622/+817
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Drop RHS of shift if effective shift is zero (#3209)Max Graey2020-10-262-8/+30
|
* Сonstant value truncation during store operation (#3117)Max Graey2020-10-262-0/+72
|
* Optimize relations of subtractions and zero (#3275)Max Graey2020-10-253-4/+254
|
* OptimizeInstructions: More 64-bit integer patterns (#3015)Max Graey2020-10-232-2/+52
| | | | | Extend ZeroRemover and optimizeAddedConstants to handle 64-bit integers as well. Use Literal.makeFromInt64 to make this easier.
* Make pops valid in tests (#3282)Heejin Ahn2020-10-236-87/+45
| | | | | | | These two tests had pops in invalid locations; pops are valid only after `catch`. This fixes those invalid wasm files. This removes pops from Os_print-stack-ir_all-features.wast too. Fixes #3213 and #3283.
* Implement v128.{load,store}{8,16,32,64}_lane instructions (#3278)Thomas Lively2020-10-227-168/+566
| | | | | | | These instructions are proposed in https://github.com/WebAssembly/simd/pull/350. This PR implements them throughout Binaryen except in the C/JS APIs and in the fuzzer, where it leaves TODOs instead. Right now these instructions are just being implemented for prototyping so adding them to the APIs isn't critical and they aren't generally available to be fuzzed in Wasm engines.
* Add float simplifications for absolute binary expressions (#3013)Max Graey2020-10-214-0/+349
|
* SimplifyLocals fuzz fix: Don't be confused by subtype assigns. (#3267)Alon Zakai2020-10-212-0/+38
| | | | | | | | We checked if the type matches when deciding if two locals are equivalent, but if the type didn't match, we forgot to reset any previously equivalent things. So we thought something was equivalent when it wasn't, see the reduced testcase. Fixes #3266
* Fuzzer: Tweak constants during mutation as well (#3272)Alon Zakai2020-10-211-25/+25
| | | | Move the tweak function to an outer location, and call it from mutate() with some probability.
* Remove old/non-working SpillPointers pass (#3261)Sam Clegg2020-10-202-1629/+0
| | | | | | | | | And associated stack.h. The current stack.h clearly doesn't work with the llvm back as it assumes the stack grows up, which means non of these has been working or used in a long time. Rather than trying to fix this unused features its probably cleaner to just remove it for now and restore it rom git history if its someone that anyone actually wants to use in the future.