diff options
author | Alon Zakai (kripken) <alonzakai@gmail.com> | 2017-02-11 13:09:04 -0800 |
---|---|---|
committer | Alon Zakai (kripken) <alonzakai@gmail.com> | 2017-02-16 22:45:35 -0800 |
commit | 41eee37bc153a68b0f0c46162e21f825d1784499 (patch) | |
tree | cc16f97c01fef7a61761bbcbecfecd53df9af365 | |
parent | c6ea79d1532face076c2dfeb8eadb58319e4e5fd (diff) | |
download | binaryen-41eee37bc153a68b0f0c46162e21f825d1784499.tar.gz binaryen-41eee37bc153a68b0f0c46162e21f825d1784499.tar.bz2 binaryen-41eee37bc153a68b0f0c46162e21f825d1784499.zip |
optimize sign-extends to ne
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 4 | ||||
-rw-r--r-- | test/passes/optimize-instructions.txt | 32 | ||||
-rw-r--r-- | test/passes/optimize-instructions.wast | 45 |
3 files changed, 79 insertions, 2 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index bb4748a97..ef18ea777 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -364,7 +364,7 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions, if (getMaxBits(ext) + extraShifts < bits) { return removeAlmostSignExt(binary); } - } else if (binary->op == EqInt32) { + } else if (binary->op == EqInt32 || binary->op == NeInt32) { if (auto* c = binary->right->dynCast<Const>()) { if (auto* ext = getSignExt(binary->left)) { // we are comparing a sign extend to a constant, which means we can use a cheaper zext @@ -374,7 +374,7 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions, c->value = c->value.and_(Literal(lowBitMask(bits))); return binary; } - if (c->value.geti32() == 0) { + if (binary->op == EqInt32 && c->value.geti32() == 0) { // equal 0 => eqz return Builder(*getModule()).makeUnary(EqZInt32, binary->left); } diff --git a/test/passes/optimize-instructions.txt b/test/passes/optimize-instructions.txt index 03f0f7074..25f2dfaa1 100644 --- a/test/passes/optimize-instructions.txt +++ b/test/passes/optimize-instructions.txt @@ -1079,4 +1079,36 @@ ) ) ) + (func $sign-ext-ne (type $4) (param $0 i32) (param $1 i32) + (drop + (i32.ne + (i32.and + (get_local $0) + (i32.const 255) + ) + (i32.const 232) + ) + ) + (drop + (i32.ne + (i32.and + (get_local $0) + (i32.const 255) + ) + (i32.const 111) + ) + ) + (drop + (i32.ne + (i32.and + (get_local $0) + (i32.const 255) + ) + (i32.and + (get_local $1) + (i32.const 255) + ) + ) + ) + ) ) diff --git a/test/passes/optimize-instructions.wast b/test/passes/optimize-instructions.wast index c59bb3ade..191450897 100644 --- a/test/passes/optimize-instructions.wast +++ b/test/passes/optimize-instructions.wast @@ -1332,4 +1332,49 @@ ) ) ) + (func $sign-ext-ne (param $0 i32) (param $1 i32) + ;; ne of sign-ext to const, can be a zext + (drop + (i32.ne + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 24) + ) + (i32.const 65000) + ) + ) + (drop + (i32.ne + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 24) + ) + (i32.const 111) + ) + ) + (drop + (i32.ne + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 24) + ) + (i32.shr_s + (i32.shl + (get_local $1) + (i32.const 24) + ) + (i32.const 24) + ) + ) + ) + ) ) |