summaryrefslogtreecommitdiff
path: root/test
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* Optimize signed division when RHS is signed minimum (#3221)Max Graey2020-10-202-3/+41
|
* Avoid name collisions in MemoryPacking (#3265)Alon Zakai2020-10-201-34/+34
| | | | | | | | | Such a collision can happen if we run the pass twice, and somehow it finds more to optimize. To make this easy, add a general utility for getting a unique name based on a root + a numeric suffix to avoid collisions. Fixes the second testcase in #3225
* Remove legacy asm.js tests (#3260)Sam Clegg2020-10-1922-13886/+0
| | | I don't think these files have been referenced since #3042 landed.
* Fix validateGlobally usage in validator, and an i64-to-i32 bug hidden by it ↵Alon Zakai2020-10-192-1/+33
| | | | | | | | | | | | | | (#3253) validateGlobally means that we can't do lookups on the module. A few places were missing that, or had it wrong. I think the reason for the wrong usages is that we used to have types on the module, and then removed that, so more is now validatable actually. This uncovered a real bug, where i64-to-32 would ignore an unreachable parameter of a call_indirect. That's bad, since if the type is i64, we need to replace it with two parameters. To fix that, just handle unreachability there, using the existing logic (which skips the call_indirect entirely in this case).
* Inlining fuzz fix: Notice ref.func function references in global inits (#3252)Alon Zakai2020-10-192-0/+23
| | | Such a reference may mean we cannot remove a function after inlining it.
* Optimize comparisons with 0/1 in boolean context (#3240)Max Graey2020-10-182-6/+45
| | | | | | | | | | i32(bool(x)) != 0 ==> i32(bool(x)) i64(bool(x)) & 1 ==> i64(bool(x)) Also: * clean up related matching rules in optimizeWithConstantOnRight * add more explanations about isPowerOf2Float & rename to isPowerOfTwoInvertibleFloat
* Remove now-redundant stack pointer manipulation passes (#3251)Sam Clegg2020-10-188-21/+14
| | | | The use of these passes was removed on the emscripten side in https://github.com/emscripten-core/emscripten/pull/12536.
* finalize: remove legacy support for "table" import (#3249)Sam Clegg2020-10-165-5/+5
| | | | | These days we always export the table, except in the case of dynamic linking, and even then we use the name `__indirect_function_table`.
* Only write explicit names to name section (#3241)Sam Clegg2020-10-152-2/+2
| | | | Fixes: #3226
* Fuzz fix for MemoryPacking on trampled data (#3222)Alon Zakai2020-10-154-3/+189
| | | | | | | | | | | | | I believe originally wasm did not allow overlapping segments, that is, where one memory segment tramples the data from a previous one. But then the spec changed its mind and we allowed it. Binaryen seems to have assumed the original case, and not checked for trampling. If there is a chance of trampling, we cannot optimize out zeros - the zero may have an effect if it tramples data from a previous segment. This does not occur in practice in LLVM output, which is why this wasn't a problem so far, I think. An existing testcase hit this issue, so I split it up.
* Assign import names consistently between text and binaryn reader (#3238)Sam Clegg2020-10-1418-50/+50
| | | | | | | | | The s-parser was assigning numbers names per-type where as the binaryn reader was using the global import count as the number to append. This change switches to use per-element count which I think it preferable as it increases the stability of the auto-generated names. e.g. memory is now always named `$mimport0`.