diff options
-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) + ) + ) + ) + ) ) |