diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 4478a7bdd3f..729a42adafb 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 == EqInt64) { + return Builder(*getModule()).makeUnary(EqZInt64, binary->left); } } // operations on all 1s 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