From 195826f8ddda7453f0414e4511fdc5e6b6b013c3 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 4 Nov 2019 13:02:37 -0800 Subject: [PATCH 1/3] wip --- src/passes/OptimizeInstructions.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 4478a7bdd3f..7d6d32eaa5f 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -1312,6 +1312,8 @@ struct OptimizeInstructions !EffectAnalyzer(getPassOptions(), binary->left) .hasSideEffects()) { return binary->right; + } else if (binary->op == Abstract::getBinary(type, Abstract::EqZ) { + return Builder(*getModule()).makeUnary(binary->left->type == i64 ? EqZInt64 : EqZInt32, binary->left); } } // operations on all 1s From 5a540955cd97eb575555aa3e7a33f768e0e80863 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 4 Nov 2019 13:07:50 -0800 Subject: [PATCH 2/3] tests --- test/passes/O.bin.txt | 13 ++++++------- .../optimize-instructions_enable-threads.txt | 16 ++++++++++++++++ .../optimize-instructions_enable-threads.wast | 18 ++++++++++++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/test/passes/O.bin.txt b/test/passes/O.bin.txt index 89a24046c75..7af8de37e31 100644 --- a/test/passes/O.bin.txt +++ b/test/passes/O.bin.txt @@ -7,9 +7,8 @@ (export "fac-opt" (func $4)) (func $0 (; 0 ;) (; has Stack IR ;) (type $0) (param $0 i64) (result i64) (if (result i64) - (i64.eq + (i64.eqz (local.get $0) - (i64.const 0) ) (i64.const 1) (i64.mul @@ -25,9 +24,8 @@ ) (func $1 (; 1 ;) (; has Stack IR ;) (type $0) (param $0 i64) (result i64) (if (result i64) - (i64.eq + (i64.eqz (local.get $0) - (i64.const 0) ) (i64.const 1) (i64.mul @@ -51,9 +49,10 @@ ) (loop $label$3 (if - (i64.ne - (local.get $0) - (i64.const 0) + (i32.eqz + (i64.eqz + (local.get $0) + ) ) (block (local.set $1 diff --git a/test/passes/optimize-instructions_enable-threads.txt b/test/passes/optimize-instructions_enable-threads.txt index f54b6ae991c..ef3122a8983 100644 --- a/test/passes/optimize-instructions_enable-threads.txt +++ b/test/passes/optimize-instructions_enable-threads.txt @@ -196,6 +196,22 @@ (i32.const 0) ) ) + (drop + (i64.eqz + (i64.const 100) + ) + ) + (drop + (i64.eq + (i64.const 0) + (i64.const 100) + ) + ) + (drop + (i64.eqz + (i64.const 0) + ) + ) (if (i32.const 123) (nop) diff --git a/test/passes/optimize-instructions_enable-threads.wast b/test/passes/optimize-instructions_enable-threads.wast index dfcaea5976a..243cb79d758 100644 --- a/test/passes/optimize-instructions_enable-threads.wast +++ b/test/passes/optimize-instructions_enable-threads.wast @@ -212,6 +212,24 @@ (i32.const 0) ) ) + (drop + (i64.eq + (i64.const 100) + (i64.const 0) + ) + ) + (drop + (i64.eq + (i64.const 0) + (i64.const 100) + ) + ) + (drop + (i64.eq + (i64.const 0) + (i64.const 0) + ) + ) (if (i32.eqz (i32.eqz From a4797e9d8f6f23474f83d6aaf05542da585c1b9a Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 4 Nov 2019 13:22:35 -0800 Subject: [PATCH 3/3] fix --- src/passes/OptimizeInstructions.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 7d6d32eaa5f..729a42adafb 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -1312,8 +1312,8 @@ struct OptimizeInstructions !EffectAnalyzer(getPassOptions(), binary->left) .hasSideEffects()) { return binary->right; - } else if (binary->op == Abstract::getBinary(type, Abstract::EqZ) { - return Builder(*getModule()).makeUnary(binary->left->type == i64 ? EqZInt64 : EqZInt32, binary->left); + } else if (binary->op == EqInt64) { + return Builder(*getModule()).makeUnary(EqZInt64, binary->left); } } // operations on all 1s