diff options
-rw-r--r-- | src/ast/properties.h | 24 | ||||
-rw-r--r-- | test/passes/optimize-instructions.txt | 30 | ||||
-rw-r--r-- | test/passes/optimize-instructions.wast | 36 |
3 files changed, 80 insertions, 10 deletions
diff --git a/src/ast/properties.h b/src/ast/properties.h index 9121deba5..097f7a8f0 100644 --- a/src/ast/properties.h +++ b/src/ast/properties.h @@ -60,11 +60,13 @@ struct Properties { if (auto* outer = curr->dynCast<Binary>()) { if (outer->op == ShrSInt32) { if (auto* outerConst = outer->right->dynCast<Const>()) { - if (auto* inner = outer->left->dynCast<Binary>()) { - if (inner->op == ShlInt32) { - if (auto* innerConst = inner->right->dynCast<Const>()) { - if (outerConst->value == innerConst->value) { - return inner->left; + if (outerConst->value.geti32() != 0) { + if (auto* inner = outer->left->dynCast<Binary>()) { + if (inner->op == ShlInt32) { + if (auto* innerConst = inner->right->dynCast<Const>()) { + if (outerConst->value == innerConst->value) { + return inner->left; + } } } } @@ -87,11 +89,13 @@ struct Properties { if (auto* outer = curr->dynCast<Binary>()) { if (outer->op == ShrSInt32) { if (auto* outerConst = outer->right->dynCast<Const>()) { - if (auto* inner = outer->left->dynCast<Binary>()) { - if (inner->op == ShlInt32) { - if (auto* innerConst = inner->right->dynCast<Const>()) { - if (outerConst->value.leU(innerConst->value).geti32()) { - return inner->left; + if (outerConst->value.geti32() != 0) { + if (auto* inner = outer->left->dynCast<Binary>()) { + if (inner->op == ShlInt32) { + if (auto* innerConst = inner->right->dynCast<Const>()) { + if (outerConst->value.leU(innerConst->value).geti32()) { + return inner->left; + } } } } diff --git a/test/passes/optimize-instructions.txt b/test/passes/optimize-instructions.txt index c8fe17cf0..49c3fca8b 100644 --- a/test/passes/optimize-instructions.txt +++ b/test/passes/optimize-instructions.txt @@ -1962,4 +1962,34 @@ ) ) ) + (func $zero-shifts-is-not-sign-ext (type $1) + (drop + (i32.eq + (i32.shr_s + (i32.shl + (i32.load16_s align=1 + (i32.const 790656516) + ) + (i32.const 0) + ) + (i32.const 0) + ) + (i32.const -5431187) + ) + ) + (drop + (i32.eq + (i32.shr_s + (i32.shl + (i32.load16_s align=1 + (i32.const 790656516) + ) + (i32.const 1) + ) + (i32.const 0) + ) + (i32.const -5431187) + ) + ) + ) ) diff --git a/test/passes/optimize-instructions.wast b/test/passes/optimize-instructions.wast index bb89d7314..88b2bcdfe 100644 --- a/test/passes/optimize-instructions.wast +++ b/test/passes/optimize-instructions.wast @@ -2359,4 +2359,40 @@ ) ) ) + (func $zero-shifts-is-not-sign-ext + (drop + (i32.eq + (i32.const -5431187) + (i32.add + (i32.const 0) + (i32.shr_s + (i32.shl + (i32.load16_s align=1 + (i32.const 790656516) + ) + (i32.const 0) + ) + (i32.const 0) + ) + ) + ) + ) + (drop + (i32.eq + (i32.const -5431187) + (i32.add + (i32.const 0) + (i32.shr_s + (i32.shl + (i32.load16_s align=1 + (i32.const 790656516) + ) + (i32.const 1) + ) + (i32.const 0) + ) + ) + ) + ) + ) ) |