summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* Optimize i32(x) % C_pot in boolean context (#3307)Max Graey2020-11-101-2/+17
| | | | | | 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-105-48/+9
|
* Canonicalize subtraction with constant on the right to addition (#3321)Max Graey2020-11-102-60/+80
| | | | | | | 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.
* Avoid boilerplate code with a big universal delegation header (#3294)Alon Zakai2020-11-092-295/+664
| | | | | | | | | | | | | | | | | | | | | | | | | To get an idea, this is a sample from the header: switch (DELEGATE_ID) { [..] case Expression::Id::BlockId: { DELEGATE_START(Block); DELEGATE_FIELD_CHILD_LIST(Block, list); DELEGATE_FIELD_SCOPE_NAME(Block, name); DELEGATE_END(Block); break; } A switch is defined (on some DELEGATE_ID that is provided). There is then a case for each expression type, calling a delegate for each field type. This allows a user to define the delegates it wants, then include this header. This uses the new header in the copying logic, where the rewrite also avoids recursion. This fixes a missing BrOnExn::sent scanning in the existing hashing/comparing code (which is what I used as a basis). When this is used there, it will fix that bug.
* Remove dead code and unused includes. NFC. (#3328)Sam Clegg2020-11-0824-92/+18
| | | Specifically try to cleanup use of asm_v_wasm.h and asmjs constants.
* Remove OptimizeCalls from PostEmscripten. NFC. (#3326)Sam Clegg2020-11-063-38/+0
| | | We no longer build modules that import `global.Math`.
* wasm2js: Remove global dict arguments to asmFunc (#3325)Sam Clegg2020-11-053-65/+16
|
* wasm2js: Remove unused argument. NFC. (#3324)Sam Clegg2020-11-051-4/+1
|
* wasm-reduce: Don't try to replace a non-number (like a reference) with a ↵Alon Zakai2020-11-051-1/+6
| | | | | Const (#3218) Also don't assume numbers are 32-bit.
* Remove remaining bits of C API tracing, which has been removed (#3322)Alon Zakai2020-11-051-1/+1
| | | It was removed in #2841
* Inlining: Slight reordering of options (#3308)Alon Zakai2020-11-042-19/+14
| | | | | | | | | | | | | | | | | This simplifies the three size-related inlining flags, so that their meanings are clearer. Also improve the comments and put them in a consistent order in both files. This should not make any difference in general, except that it is now possible to have oneCallerInlineMaxSize > flexibleInlineMaxSize, and we will inline a function with one caller if flexibleInlineMaxSize < FUNCTION_SIZE <= oneCallerInlineMaxSize which we would not before. As the defaults of the flags didn't fit that case, this should not change anything for anyone not passing in those specific inlining flags. For people that pass in those flags, this PR makes more things possible. Resolves the FIXME in that code, and is a refactoring before some more inlining work I have planned.
* Optimize signed / unsigned relationals when RHS is min or max constant (#3314)Max Graey2020-11-041-7/+89
|
* More precise implicitTrap detection for binary extressions (#3312)Max Graey2020-11-041-78/+65
| | | | | | | 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.
* Remove unused wasm-object.h (#3319)Thomas Lively2020-11-031-40/+0
|
* Slight refactoring of handOptimize (#3305)Max Graey2020-11-031-15/+15
| | | Move the checks for most unoptimizable expression types out into visitExpression and simplify some other code.
* Optimize x * -1.0 in non-fastMath case (#3315)Max Graey2020-11-031-3/+12
| | | | | | | | | | | | | | 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-022-10/+20
| | | We can only pack memory if we know it is zero-filled before us.
* Fix usage of `allocate` in JS (no longer takes a type argument) (#3311)Daniel Wirtz2020-11-021-3/+3
|
* RemoveUnusedBrs: Properly check for effects in selectify() (#3310)Alon Zakai2020-11-011-11/+25
| | | | | 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-311-348/+85
| | | | | | | 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-301-4/+82
|
* Standardize NaNs in the interpreter, when there is nondeterminism (#3298)Alon Zakai2020-10-301-62/+72
| | | | | | | 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-303-13/+32
| | | Fixed bug in memory64-lowering pass for memory.size/grow
* Fold subtraction of sums or differences from constants (#3295)Max Graey2020-10-292-0/+45
| | | | | `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-291-0/+3
| | | | 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-293-29/+3
| | | | | | 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-291-2/+13
|
* Use RAII in fuzzer for function context creation (#3296)Alon Zakai2020-10-291-62/+64
| | | Followup to #3276
* Remove support for emscripten legacy PIC ABI (#3299)Sam Clegg2020-10-299-222/+6
|
* Fix pow2 util and avoid pow2 for left shifting in ZeroRemover (#3293)Max Graey2020-10-282-9/+11
| | | | | | | | 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-2813-14/+421
| | | | | | | 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-271-12/+25
|
* Replace x * 2 with x + x for floats (#3016)Max Graey2020-10-271-0/+13
| | | But only when doing so doesn't require adding a new local.
* Rename unmodifiedImportedMemory => zeroFilledMemory (#3285)Alon Zakai2020-10-272-7/+7
|
* Reduce boilerplate with a C macro for class delegations. NFC (#3290)Alon Zakai2020-10-272-784/+120
| | | Split off from #3264
* DWARF: Fix handling of the end of control flow instructions (#3288)Alon Zakai2020-10-274-26/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-273-29/+240
| | | | | | | | | | | | | | | | | | | | | | | | | 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-2714-0/+28
| | | | | | 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-264-493/+109
| | | | | | | | | | | | | | | | | | | | | | | | | 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-261-0/+8
|
* Сonstant value truncation during store operation (#3117)Max Graey2020-10-261-0/+13
|
* [NFC] `using namespace Abstract` to make matchers more compact (#3284)Thomas Lively2020-10-2610-115/+96
| | | | | | | | | This change makes matchers in OptimizeInstructions more compact and readable by removing the explicit `Abstract::` namespace from individual operations. In some cases, this makes multi-line matcher expressions fit on a single line. This change is only possible because it also adds an explicit "RMW" prefix to each element of the `AtomicRMWOp` enumeration. Without that, their names conflicted with the names of Abstract ops.
* Optimize relations of subtractions and zero (#3275)Max Graey2020-10-251-15/+102
|
* OptimizeInstructions: More 64-bit integer patterns (#3015)Max Graey2020-10-231-42/+56
| | | | | Extend ZeroRemover and optimizeAddedConstants to handle 64-bit integers as well. Use Literal.makeFromInt64 to make this easier.
* Fuzzer: Fix wasm2c name mangling (#3228)Alon Zakai2020-10-231-27/+56
| | | | This is necessary for cases where the input has an export name that needs mangling, like a name with - (common in the spec test suite).
* Avoid UB in pow2 func (#3243)Max Graey2020-10-231-1/+1
|
* Handle get/setTempRet0 in fuzzer support (#3279)Alon Zakai2020-10-231-0/+13
| | | | | | | | This avoids it printing a warning and doing nothing for them. It also increases coverage, for checking 64-bit return values, but any such bug would have already been found already, I think (as we ignored the high bits), so likely the fuzzer is not emitting such things when running JS at least.
* Remove now-redundant --mutable-sp flag from finalize (#3273)Sam Clegg2020-10-231-8/+0
|
* Implement v128.{load,store}{8,16,32,64}_lane instructions (#3278)Thomas Lively2020-10-2223-9/+509
| | | | | | | 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-212-0/+54
|