diff options
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 14 | ||||
-rw-r--r-- | test/passes/optimize-instructions.txt | 12 | ||||
-rw-r--r-- | test/passes/optimize-instructions.wast | 4 |
3 files changed, 26 insertions, 4 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 0b54f9756..7f1483371 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -314,18 +314,24 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions, } } else if (auto* store = curr->dynCast<Store>()) { // stores of fewer bits truncates anyhow - if (auto* value = store->value->dynCast<Binary>()) { - if (value->op == AndInt32) { - if (auto* right = value->right->dynCast<Const>()) { + if (auto* binary = store->value->dynCast<Binary>()) { + if (binary->op == AndInt32) { + if (auto* right = binary->right->dynCast<Const>()) { if (right->type == i32) { auto mask = right->value.geti32(); if ((store->bytes == 1 && mask == 0xff) || (store->bytes == 2 && mask == 0xffff)) { - store->value = value->left; + store->value = binary->left; } } } } + } else if (auto* unary = store->value->dynCast<Unary>()) { + if (unary->op == WrapInt64) { + // instead of wrapping to 32, just store some of the bits in the i64 + store->valueType = i64; + store->value = unary->value; + } } } return nullptr; diff --git a/test/passes/optimize-instructions.txt b/test/passes/optimize-instructions.txt index 73076b0c5..ca5898e73 100644 --- a/test/passes/optimize-instructions.txt +++ b/test/passes/optimize-instructions.txt @@ -289,6 +289,18 @@ (i32.const 65534) ) ) + (i64.store8 + (i32.const 11) + (i64.const 1) + ) + (i64.store16 + (i32.const 11) + (i64.const 2) + ) + (i64.store32 + (i32.const 11) + (i64.const 3) + ) ) (func $and-neg1 (type $1) (drop diff --git a/test/passes/optimize-instructions.wast b/test/passes/optimize-instructions.wast index 9701941c7..e6d18240d 100644 --- a/test/passes/optimize-instructions.wast +++ b/test/passes/optimize-instructions.wast @@ -266,6 +266,10 @@ (i32.store8 (i32.const 9) (i32.and (i32.const -2) (i32.const 254))) (i32.store16 (i32.const 10) (i32.and (i32.const -3) (i32.const 65535))) (i32.store16 (i32.const 11) (i32.and (i32.const -4) (i32.const 65534))) + ;; + (i32.store8 (i32.const 11) (i32.wrap/i64 (i64.const 1))) + (i32.store16 (i32.const 11) (i32.wrap/i64 (i64.const 2))) + (i32.store (i32.const 11) (i32.wrap/i64 (i64.const 3))) ) (func $and-neg1 (drop (i32.and (i32.const 100) (i32.const -1))) |