summaryrefslogtreecommitdiff
path: root/test
Commit message (Collapse)AuthorAgeFilesLines
* LegalizeJSInterface: Remove illegal imports once they are no longer used (#3815)Sam Clegg2021-04-163-8/+3
| | | | | | | | | This prevents used imports which also happen to have duplicate names and therefore cannot be provided by wasm (JS is happen to fill these in with polymorphic JS functions). I noticed this when working on emscripten and directly hooking modules together. I was seeing failures, but not in release builds (because wasm-opt would mop these up in release builds).
* [Wasm GC] Fix precompute on GC data (#3810)Alon Zakai2021-04-153-17/+487
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes precomputation on GC after #3803 was too optimistic. The issue is subtle. Precompute will repeatedly evaluate expressions and propagate their values, flowing them around, and it ignores side effects when doing so. For example: (block ..side effect.. (i32.const 1) ) When we evaluate that we see there are side effects, but regardless of them we know the value flowing out is 1. So we can propagate that value, if it is assigned to a local and read elsewhere. This is not valid for GC because struct.new and array.new have a "side effect" that is noticeable in the result. Each time we call struct.new we get a new struct with a new address, which ref.eq can distinguish. So when this pass evaluates the same thing multiple times it will get a different result. Also, we can't precompute a struct.get even if we know the struct, not unless we know the reference has not escaped (where a call could modify it). To avoid all that, do not precompute references, aside from the trivially safe ones like nulls and function references (simple constants that are the same each time we evaluate the expression emitting them). precomputeExpression() had a minor bug which this fixes. It checked the type of the expression to see if we can create a constant for it, but really it should check the value - since (separate from this PR) we have no way to emit a "constant" for a struct etc. Also that only matters if replaceExpression is true, that is, if we are replacing with a constant; if we just want the value internally, we have no limit on that. Also add Literal support for comparing GC refs, which is used by ref.eq. Without that tiny fix the tests here crash. This adds a bunch of tests, many for corner cases that we don't handle (since the PR makes us not propagate GC references). But they should be helpful if/when we do, to avoid the mistakes in #3803
* Rename emscripten metadata key to reflect new unmangled names (#3813)Sam Clegg2021-04-1533-33/+33
| | | | | | Turns out just removing the mangling wasn't enough for emscripten to support both before and after versions. See https://github.com/WebAssembly/binaryen/pull/3785
* Remove renaming of __wasm_call_ctors (#3811)Sam Clegg2021-04-154-8/+8
| | | See https://github.com/emscripten-core/emscripten/issues/13893
* Remove final remnants of name mangling from wasm-emscripten (#3785)Sam Clegg2021-04-1510-41/+41
| | | See https://github.com/emscripten-core/emscripten/pull/13847
* [Wasm GC] Do not inline a function with an RTT parameter (#3808)Alon Zakai2021-04-142-0/+24
| | | | | Inlined parameters become locals, and rtts cannot be handled as locals, unlike non-nullable values which we can at least fix up. So do not inline functions with rtt params.
* [Wasm GC] Full precompute support for GC (#3803)Alon Zakai2021-04-132-85/+50
| | | | | | | | | | | | The precompute pass ignored all reference types, but that was overly pessimistic: we can precompute some of them, namely a null and a reference to a function are fully precomputable, etc. To allow that to work, add missing integration in getFallthrough as well. With this, we can precompute quite a lot of field accesses in the existing -Oz testcase, as can be seen from the output. That testcase runs --fuzz-exec so it prints out all those logged values, proving they have not changed.
* Fuzzer: Distinguish traps from host limitations (#3801)Alon Zakai2021-04-122-1/+29
| | | | | | | | | Host limitations are arbitrary and can be modified by optimizations, so ignore them. For example, if the optimizer removes allocations then a host limit on an allocation error may vanish. Or, an optimization that removes recursion and replaces it with a loop may avoid a host limit on call depth (that is not done currently, but might some day). This removes a class of annoying false positives in the fuzzer.
* [Wasm GC] Optimize away unnecessary non-null assertions (#3800)Alon Zakai2021-04-121-9/+82
| | | | | | ref.as_non_null is not needed if the value flows into a place that traps on null anyhow. We replace a trap on one instruction with a trap on another, but we allow such things (and even changing trap types, which does not happen here).
* Rename SIMD extending load instructions (#3798)Daniel Wirtz2021-04-122-33/+15
| | | | | | | | | Renames the SIMD instructions * LoadExtSVec8x8ToVecI16x8 -> Load8x8SVec128 * LoadExtUVec8x8ToVecI16x8 -> Load8x8UVec128 * LoadExtSVec16x4ToVecI32x4 -> Load16x4SVec128 * LoadExtUVec16x4ToVecI32x4 -> Load16x4UVec128 * LoadExtSVec32x2ToVecI64x2 -> Load32x2SVec128 * LoadExtUVec32x2ToVecI64x2 -> Load32x2UVec128
* Rename various SIMD load instructions (#3795)Daniel Wirtz2021-04-112-7/+7
| | | | | | | | | Renames the SIMD instructions * LoadSplatVec8x16 -> Load8SplatVec128 * LoadSplatVec16x8 -> Load16SplatVec128 * LoadSplatVec32x4 -> Load32SplatVec128 * LoadSplatVec64x2 -> Load64SplatVec128 * Load32Zero -> Load32ZeroVec128 * Load64Zero -> Load64ZeroVec128
* RefFunc: Validate that the type is non-nullable, and avoid possible bugs in ↵Alon Zakai2021-04-081-1/+3
| | | | | | | | the builder (#3790) The builder can receive a HeapType so that callers don't need to set non-nullability themselves. Not NFC as some of the callers were in fact still making it nullable.
* Add v128.load/storeN_lane SIMD instructions to C/JS API (#3784)Daniel Wirtz2021-04-084-0/+275
| | | | | | | | | | | Adds C/JS APIs for the SIMD instructions * Load8LaneVec128 (was LoadLaneVec8x16) * Load16LaneVec128 (was LoadLaneVec16x8) * Load32LaneVec128 (was LoadLaneVec32x4) * Load64LaneVec128 (was LoadLaneVec64x2) * Store8LaneVec128 (was StoreLaneVec8x16) * Store16LaneVec128 (was StoreLaneVec16x8) * Store32LaneVec128 (was StoreLaneVec32x4) * Store64LaneVec128 (was StoreLaneVec64x2)
* Add v128.load32/64_zero SIMD instructions to C/JS API (#3783)Daniel Wirtz2021-04-084-0/+42
| | | | | Adds C/JS APIs for the SIMD instructions * Load32Zero * Load64Zero
* Add new SIMD multiplication instructions to C/JS API (#3782)Daniel Wirtz2021-04-084-0/+260
| | | | | | | | | | | | | | | | Adds C/JS APIs for the SIMD instructions * Q15MulrSatSVecI16x8 * ExtMulLowSVecI16x8 * ExtMulHighSVecI16x8 * ExtMulLowUVecI16x8 * ExtMulHighUVecI16x8 * ExtMulLowSVecI32x4 * ExtMulHighSVecI32x4 * ExtMulLowUVecI32x4 * ExtMulHighUVecI32x4 * ExtMulLowSVecI64x2 * ExtMulHighSVecI64x2 * ExtMulLowUVecI64x2 * ExtMulHighUVecI64x2
* Add new SIMD conversion instructions to C/JS API (#3781)Daniel Wirtz2021-04-084-0/+102
| | | | | | | | | Adds C/JS APIs for the SIMD instructions * ConvertLowSVecI32x4ToVecF64x2 * ConvertLowUVecI32x4ToVecF64x2 * TruncSatZeroSVecF64x2ToVecI32x4 * TruncSatZeroUVecF64x2ToVecI32x4 * DemoteZeroVecF64x2ToVecF32x4 * PromoteLowVecF32x4ToVecF64x2
* Add iNxM.extadd_pairwise_* SIMD instructions to C/JS API (#3780)Daniel Wirtz2021-04-084-0/+68
| | | | | | | Adds C/JS APIs for the SIMD instructions * ExtAddPairwiseSVecI8x16ToI16x8 * ExtAddPairwiseUVecI8x16ToI16x8 * ExtAddPairwiseSVecI16x8ToI32x4 * ExtAddPairwiseUVecI16x8ToI32x4
* Add i64x2.extend_low/high_* SIMD instructions to C/JS API (#3778)Daniel Wirtz2021-04-074-0/+68
| | | | | | | Adds C/JS APIs for the SIMD instructions * ExtendLowSVecI32x4ToVecI64x2 * ExtendHighSVecI32x4ToVecI64x2 * ExtendLowUVecI32x4ToVecI64x2 * ExtendHighUVecI32x4ToVecI64x2
* Add various SIMD instructions to C/JS API (#3777)Daniel Wirtz2021-04-074-0/+188
| | | | | | | | | | | | | Adds C/JS APIs for the SIMD instructions * PopcntVecI8x16 * AbsVecI64x2 * AllTrueVecI64x2 * BitmaskVecI64x2 * EqVecI64x2 * NeVecI64x2 * LtSVecI64x2 * GtSVecI64x2 * LeSVecI64x2 * GeSVecI64x2
* [GC] Do not crash on unreasonable GC array allocations in interpreter; trap ↵Alon Zakai2021-04-072-4/+19
| | | | | | | | | | (#3559) The spec does not mention traps here, but this is like a JS VM trapping on OOM - a runtime limitation is reached. As these are not specced traps, I did not add them to effects.h. Note how as a result the optimizer happily optimizes into a nop an unused allocation of an array of size unsigned(-1), which is the behavior we want.
* [RT] Add type to tables and element segments (#3763)Abbas Mashayekh2021-04-066-8/+318
|
* Emit dollar signs when relevant while debugging s-expression elements (#3693)Alon Zakai2021-04-062-6/+6
| | | | This is just noticeable when debugging locally and doing a quick print to stdout.
* Fuzzing in JS VMs: Print types when we have nothing better (#3773)Alon Zakai2021-04-061-1/+2
| | | | | | | | | | | | | This matches #3747 which makes us not log out reference values, instead we print just their types. This also prints a type for non-reference things, replacing a previous exception, which affects things like SIMD and BigInts, but those trap anyhow at the JS boundary I believe (or did that change for SIMD?). Anyhow, printing the type won't give a false "ok" when comparing wasm2js output to the interpreter, assuming the interpreter prints out a value and not just a type (which is the case). We could try to do better, but this code is on the JS side, where we don't have the type - just a string representation of it, which we'd need to parse etc.
* Update SIMD names and opcodes (#3771)Thomas Lively2021-04-0518-2361/+1771
| | | | Also removes experimental SIMD instructions that were not included in the final spec proposal.
* Reorder global definitions in Print pass (#3770)Abbas Mashayekh2021-04-0274-154/+154
| | | | This is needed to make sure globals are printed before element segments, where `global.get` can appear both as offset and an expression.
* Improve a test from binary to text (#3769)Alon Zakai2021-04-014-1/+13
| | | | Instead of specifying the features in the wasm, enable them using flags. This allows the testcase to be in text.
* Fix type canonicalization bugs (#3761)Thomas Lively2021-04-013-4/+113
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When canonical heap types were already present in the global store, for example during the --roundtrip pass, type canonicalization was not working correctly. The issue was that the GlobalCanonicalizer was replacing temporary HeapTypes with their canonical equivalents one type at a time, but the act of replacing a temporary HeapType use with a canonical HeapType use could change the shape of later HeapTypes, preventing them from being correctly matched with their canonical counterparts. This PR fixes that problem by computing all the temporary-to-canonical heap type replacements before executing them. To avoid a similar problem when canonicalizing Types, one solution would have been to pre-calculate the replacements before executing them just like with the HeapTypes, but that would have required either complex bookkeeping or moving temporary Types into the global store when they are first canonicalized. That would have been complicated because unlike for temporary HeapTypeInfos, the unique_pointer to temporary TypeInfos is not readily available. This PR instead switches back to using pointer-identity based equality and hashing for TypeInfos, which works because we only ever canonicalize Types with canonical children. This change should be a nice performance improvement as well. Another bug this PR fixes is that shape hashing and equality considered BasicKind HeapTypes to be different from their corresponding BasicHeapTypes, which meant that canonicalization could produce different types for the same type definition depending on whether the definition used a TypeBuilder or not. The fix is to pre-canonicalize BasicHeapTypes (and Types that have them as children) during shape hashing and equality. The same mechanism is also used to simplify Store's canonicalization. Fixes #3736.
* Catch bad tuple.extract index in parser (#3766)Thomas Lively2021-03-311-0/+16
| | | | Previously an out-of-bounds index would result in an out-of-bounds read during finalization of the tuple.extract expression.
* Remove old syntax from table and elem in parser (#3753)Abbas Mashayekh2021-03-317-10/+10
| | | | | | | We've been keeping old syntax in the text format parser although they've been removed from the parser and hardly any test case relies on them. This PR will remove old syntax support for tables and element segments and simplify the corresponding parser functions. A few test files were affected by this that are updated.
* [Wasm GC] Optimize RefCast + ignore-implicit-traps (#3748)Alon Zakai2021-03-301-0/+139
| | | | | | | If we are ignoring implicit traps, and if the cast is from a subtype to a supertype, then we ignore the possible RTT-related inconsistency and can just drop the cast. See #3636
* SetGlobals pass (#3750)Alon Zakai2021-03-303-0/+12
| | | | | | This allows changing a global's value on the commandline in an easy way. In some toolchains this is useful as the build can contain a global that indicates something like a logging level, which this can customize.
* Scan all module-level code in collectHeapTypes() (#3752)Alon Zakai2021-03-301-0/+11
| | | | | The key fix here is to call walkModuleCode so that we pick up on types that appear only in the table and nowhere else. The rest of the patch refactors the code so that that is practical.
* Fix LegalizeJSInterface with RefFuncs (#3749)Alon Zakai2021-03-304-7/+10
| | | | | | | | | | | | | | | | | | | | | | | | This code used to remove functions it no longer thinks are needed. That is, if it adds a legalized version of an import, it would remove the illegal one which is no longer needed. To avoid removing an illegal import that is still used it checked for ref.func appearances. But this was bad in two ways: We need to legalize the ref.funcs too. We can't call an illegal import in any way, not using a direct call, indirect call, or call by reference of a ref.func. It's silly to remove unneeded functions here. We have a pass for that. This removes the removal of functions, and adds proper updating of ref.calls, which means to call the stub function that looks like the original import, but that calls the legalized one and connects things up properly, exactly the same way as other calls. Also remove code that checked if we were in the stub/thunk and to not replace the call there. That code is not needed: no one will ever call the illegal import, so we do not need to be careful about preserving such calls.
* Remove passive keyword from data segment parser (#3757)Abbas Mashayekh2021-03-3028-268/+414
| | | | | | | | 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
* Fuzzing: Minor execution-results.h fixes (#3747)Alon Zakai2021-03-302-4/+4
| | | | | | | | | | | | Log out an i64 as two i32s. That keeps the output consistent regardless of whether we legalize. Do not print a reference result. The printed value cannot be compared, as funcref(10) (where 10 is the index of the function) is not guaranteed to be the same after opts. Trap when trying to call an export with a nondefaultable type (instead of asserting when trying to create zeros for it).
* [Wasm GC] Optimize RefIs and RefAs when the type lets us (#3725)Alon Zakai2021-03-301-0/+370
| | | | | | | | | This is similar to the optimization of BrOn in #3719 and #3724. When the type tells us the kind of input we have, we can tell at compile time what result we'll get, like ref.is_func of something with type (ref func) will always return 1, etc. There are some code size and perf tradeoffs that should be looked into more and are marked as TODOs.
* [Wasm GC] Heap reads/writes are reads/writes of global state (#3755)Alon Zakai2021-03-301-0/+35
| | | | | | We missed that in effects.h, with the result that sets could look like they had no side effects. Fixes #3754
* Fix DeadArgumentElimination pass on non-nullable locals (#3751)Alon Zakai2021-03-302-0/+21
| | | | | | | | | | | In this case, there is a natural place to fix things up right after removing a parameter (which is where a local gets added). Doing it there avoids doing work on all functions unnecessarily. Note that we could do something even simpler here than calling the generic code: the parameter was not used, so the new local is not used, and we could just change the type of the local or not add it at all. Those would be slightly more code though, and add complexity to the parameter removal method itself.
* OptimizeInstructions: bool(x) xor 1 ==> !bool(x) (#3741)Alon Zakai2021-03-302-6/+38
| | | | | | | | | This was noticed by samparker on LLVM: https://reviews.llvm.org/D99171 This is apparently a pattern LLVM emits, and doing it there helps by 1-2% on the real-world Bullet Physics codebase. Seems worthwhile doing here as well.
* LUBs (#3731)Thomas Lively2021-03-297-22/+385
| | | | | | | This is a partial revert of #3669, which removed the old implementation of Type::getLeastUpperBound that did not correctly handle recursive types. The new implementation in this PR uses a TypeBuilder to construct LUBs and for recursive types, it returns a temporary HeapType that has not yet been fully constructed to break what would otherwise be infinite recursions.
* Scan module-level code in necessary places (#3744)Alon Zakai2021-03-295-3/+75
| | | | | | | | | | | | | | | | | | Several old passes like DeadArgumentElimination and DuplicateFunctionElimination need to look at all ref.funcs, and they scanned functions for that, but that is not enough as such an instruction might appear in a global initializer. To fix this, add a walkModuleCode method. walkModuleCode is useful when doing the pattern of creating a function-parallel pass to scan functions quickly, but we also want to do the same scanning of code at the module level. This allows doing so in a single line. (It is also possible to just do walk() on the entire module, which will find all code, but that is not function-parallel. Perhaps we should have a walkParallel() option to simplify this further in a followup, and that would call walkModuleCode afterwards etc.) Also add some missing validation and comments in the validator about issues that I noticed in relation to the new testcases here.
* [Wasm GC] Fix SSA pass on non-nullable parameters (#3745)Alon Zakai2021-03-291-0/+34
| | | | If such a parameter is written to then we create a new local for each such write, and must handle non-nullability of those new locals.
* handleNonNullableLocals(): Do not modify params (#3740)Alon Zakai2021-03-291-0/+22
| | | | Parameters can be non-nullable, and must stay so if they began as such. By mistake we modified them with the vars.
* Inlining: Always inline single-use functions (#3730)Alon Zakai2021-03-2916-1982/+1960
| | | | | | | | | | | | | | | | 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.
* [Wasm GC] Add a Name-Types pass (#3735)Alon Zakai2021-03-251-0/+12
| | | | | The pass gives a simple short name to each type, $type$N. This can be useful in debugging, to avoid the autogenerated names which can be very long.
* Fix binary reading of tuples containing non-nullable types (#3734)Alon Zakai2021-03-251-0/+46
| | | | | | | | We must write them to a tuple with nullable types, then fix that up when reading. This is similar to what we do in handleNonNullableLocals, except that it operates on the entire tuple type, so it can't share that code. This fixes a regression from #3710 that was harder to notice by the fuzzer until now.
* Fix nondefaultability of Tuple types (#3733)Alon Zakai2021-03-251-0/+9
| | | | | | | This looks like a pre-existing issue to #3731, but the testcase only fails on that PR for a reason I did not investigate in depth, so it should land first. Also fix the check for nondefaultability in the fuzzer.
* Flat IR: Allow ref.as_non_null in nested positions (#3732)Alon Zakai2021-03-251-0/+43
| | | | | | We can't disallow it, as its result is non-null which we can't spill to a local. This may cause issues eventually in the combination of GC + flatten, but I don't expect it to. If it does we may need to revisit.
* [Wasm GC] Properly validate struct.new number of operands (#3726)Alon Zakai2021-03-251-0/+26
|
* Refactor TypeBuilder (#3728)Thomas Lively2021-03-242-47/+75
| | | | | | | | | | Makes TypeBuilders growable, adds a `getTempHeapType` method, allows the `getTemp*Type` methods to take arbitrary temporary or canonical HeapTypes rather than just an index, and allows BasicHeapTypes to be assigned to TypeBuilder slots. All of these changes are necessary for the upcoming re-implementation of equirecursive LUB calculation. Also adds a new utility to TypeBuilder for using `operator[]` as an intuitive and readable wrapper around the `getTempHeapType` and `setHeapType` methods.