diff --git a/src/module.ts b/src/module.ts index d8396671d9..9dad851750 100644 --- a/src/module.ts +++ b/src/module.ts @@ -1106,10 +1106,16 @@ export class Module { var func = this.addTemporaryFunction(type, null, expr); var names = this.cachedPrecomputeNames; if (!names) { - this.cachedPrecomputeNames = names = allocI32Array([ this.allocStringCached("precompute") ]); + this.cachedPrecomputeNames = names = allocI32Array([ + this.allocStringCached("vacuum"), + this.allocStringCached("precompute") + ]); } - _BinaryenFunctionRunPasses(func, this.ref, names, 1); + _BinaryenFunctionRunPasses(func, this.ref, names, 2); expr = _BinaryenFunctionGetBody(func); + if (_BinaryenExpressionGetId(expr) == ExpressionId.Return) { + expr = _BinaryenReturnGetValue(expr); + } this.removeTemporaryFunction(); // reset optimize levels to previous @@ -1194,7 +1200,7 @@ export class Module { var nested1: ExpressionRef, nested2: ExpressionRef; - switch (_BinaryenExpressionGetId(expr)) { + switch (_BinaryenExpressionGetId(expr)) { case ExpressionId.Const: { switch (_BinaryenExpressionGetType(expr)) { case NativeType.I32: { @@ -1562,12 +1568,12 @@ export class Relooper { } // export function hasSideEffects(expr: ExpressionRef): bool { -// switch (_BinaryenExpressionGetId(expr = getPtr(expr))) { -// case ExpressionId.GetLocal: -// case ExpressionId.GetGlobal: +// // TODO: there's more +// switch (_BinaryenExpressionGetId(expr)) { +// case ExpressionId.LocalGet: +// case ExpressionId.GlobalGet: // case ExpressionId.Const: -// case ExpressionId.Nop: -// case ExpressionId.Unreachable: { +// case ExpressionId.Nop: { // return false; // } // case ExpressionId.Block: { diff --git a/tests/compiler/instanceof.untouched.wat b/tests/compiler/instanceof.untouched.wat index 7136f6e13a..31257b0dd9 100644 --- a/tests/compiler/instanceof.untouched.wat +++ b/tests/compiler/instanceof.untouched.wat @@ -19,56 +19,20 @@ (export "memory" (memory $0)) (start $start) (func $instanceof/isI32 (; 1 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - drop i32.const 1 - if - i32.const 1 - return - else - i32.const 0 - return - end - unreachable + return ) (func $instanceof/isI32 (; 2 ;) (type $FUNCSIG$id) (param $0 f64) (result i32) - local.get $0 - drop i32.const 0 - if - i32.const 1 - return - else - i32.const 0 - return - end - unreachable + return ) (func $instanceof/isI32 (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - drop i32.const 0 - if - i32.const 1 - return - else - i32.const 0 - return - end - unreachable + return ) (func $instanceof/isI32 (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - drop i32.const 0 - if - i32.const 1 - return - else - i32.const 0 - return - end - unreachable + return ) (func $~lib/rt/stub/__retain (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 diff --git a/tests/compiler/std/arraybuffer.untouched.wat b/tests/compiler/std/arraybuffer.untouched.wat index efd6512728..17c7ea52f2 100644 --- a/tests/compiler/std/arraybuffer.untouched.wat +++ b/tests/compiler/std/arraybuffer.untouched.wat @@ -3320,138 +3320,7 @@ drop local.get $0 if - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end + nop end i32.const 0 local.set $1 @@ -3462,90 +3331,7 @@ (func $~lib/arraybuffer/ArrayBuffer.isView (; 31 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 if - local.get $0 - drop - i32.const 0 - if - i32.const 1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - return - end + nop end i32.const 0 ) @@ -3556,138 +3342,12 @@ drop local.get $0 if - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop i32.const 1 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end + local.set $1 local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end + call $~lib/rt/pure/__release + local.get $1 + return end i32.const 0 local.set $1 @@ -3702,138 +3362,12 @@ drop local.get $0 if - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop i32.const 1 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end + local.set $1 local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end + call $~lib/rt/pure/__release + local.get $1 + return end i32.const 0 local.set $1 @@ -3848,138 +3382,12 @@ drop local.get $0 if - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop - i32.const 0 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end - local.get $0 - drop i32.const 1 - if - i32.const 1 - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - local.get $1 - return - end + local.set $1 + local.get $0 + call $~lib/rt/pure/__release + local.get $1 + return end i32.const 0 local.set $1