diff options
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index f467b395e..7547f332a 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -223,6 +223,19 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions, return Builder(*getModule()).makeUnary(EqZInt32, binary->right); } } + } else if (binary->op == AndInt32) { + if (auto* load = binary->left->dynCast<Load>()) { + if (auto* right = binary->right->dynCast<Const>()) { + if (right->type == i32) { + auto mask = right->value.geti32(); + if ((load->bytes == 1 && mask == 0xff) || + (load->bytes == 2 && mask == 0xffff)) { + load->signed_ = false; + return load; + } + } + } + } } } else if (auto* unary = curr->dynCast<Unary>()) { // de-morgan's laws @@ -294,6 +307,21 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions, if (br->condition) { br->condition = optimizeBoolean(br->condition); } + } 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 (right->type == i32) { + auto mask = right->value.geti32(); + if ((store->bytes == 1 && mask == 0xff) || + (store->bytes == 2 && mask == 0xffff)) { + store->value = value->left; + } + } + } + } + } } return nullptr; } |