diff options
Diffstat (limited to 'src/ast')
-rw-r--r-- | src/ast/bits.h | 3 | ||||
-rw-r--r-- | src/ast/properties.h | 8 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/ast/bits.h b/src/ast/bits.h index 11cf7b06d..0aee50ffe 100644 --- a/src/ast/bits.h +++ b/src/ast/bits.h @@ -51,7 +51,8 @@ struct Bits { WASM_UNREACHABLE(); } - static Index getEffectiveShifts(Const* amount) { + static Index getEffectiveShifts(Expression* expr) { + auto* amount = expr->cast<Const>(); if (amount->type == i32) { return getEffectiveShifts(amount->value.geti32(), i32); } else if (amount->type == i64) { diff --git a/src/ast/properties.h b/src/ast/properties.h index 097f7a8f0..8c8655c07 100644 --- a/src/ast/properties.h +++ b/src/ast/properties.h @@ -79,7 +79,7 @@ struct Properties { // gets the size of the sign-extended value static Index getSignExtBits(Expression* curr) { - return 32 - curr->cast<Binary>()->right->cast<Const>()->value.geti32(); + return 32 - Bits::getEffectiveShifts(curr->cast<Binary>()->right); } // Check if an expression is almost a sign-extend: perhaps the inner shift @@ -93,7 +93,7 @@ struct Properties { 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()) { + if (Bits::getEffectiveShifts(outerConst) <= Bits::getEffectiveShifts(innerConst)) { return inner->left; } } @@ -109,8 +109,8 @@ struct Properties { // gets the size of the almost sign-extended value, as well as the // extra shifts, if any static Index getAlmostSignExtBits(Expression* curr, Index& extraShifts) { - extraShifts = curr->cast<Binary>()->left->cast<Binary>()->right->cast<Const>()->value.geti32() - - curr->cast<Binary>()->right->cast<Const>()->value.geti32(); + extraShifts = Bits::getEffectiveShifts(curr->cast<Binary>()->left->cast<Binary>()->right) - + Bits::getEffectiveShifts(curr->cast<Binary>()->right); return getSignExtBits(curr); } |