summaryrefslogtreecommitdiff
path: root/src/passes/OptimizeInstructions.cpp
diff options
context:
space:
mode:
authorMax Graey <maxgraey@gmail.com>2020-10-26 22:27:54 +0200
committerGitHub <noreply@github.com>2020-10-26 13:27:54 -0700
commitc8eeeeaed96d7753efe1b597c1b6b68098d82c79 (patch)
tree047d6b5a776116c1864c27dcd0370a5c959015fc /src/passes/OptimizeInstructions.cpp
parent019b0ef15e966ecafa6cdfa357b00de09c332633 (diff)
downloadbinaryen-c8eeeeaed96d7753efe1b597c1b6b68098d82c79.tar.gz
binaryen-c8eeeeaed96d7753efe1b597c1b6b68098d82c79.tar.bz2
binaryen-c8eeeeaed96d7753efe1b597c1b6b68098d82c79.zip
Сonstant value truncation during store operation (#3117)
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r--src/passes/OptimizeInstructions.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index 982f99a04..0ce1f5f95 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -826,6 +826,19 @@ struct OptimizeInstructions
optimizeMemoryAccess(load->ptr, load->offset);
} else if (auto* store = curr->dynCast<Store>()) {
optimizeMemoryAccess(store->ptr, store->offset);
+ if (store->valueType.isInteger()) {
+ // truncates constant values during stores
+ // (i32|i64).store(8|16|32)(p, C) ==>
+ // (i32|i64).store(8|16|32)(p, C & mask)
+ if (auto* c = store->value->dynCast<Const>()) {
+ if (store->valueType == Type::i64 && store->bytes == 4) {
+ c->value = c->value.and_(Literal(uint64_t(0xffffffff)));
+ } else {
+ c->value = c->value.and_(Literal::makeFromInt32(
+ Bits::lowBitMask(store->bytes * 8), store->valueType));
+ }
+ }
+ }
// stores of fewer bits truncates anyhow
if (auto* binary = store->value->dynCast<Binary>()) {
if (binary->op == AndInt32) {