diff options
author | Alon Zakai <azakai@google.com> | 2020-09-22 08:48:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-22 08:48:47 -0700 |
commit | 0f9339d4e9cfce796d5056c962a183680a19c8ea (patch) | |
tree | 3a75d0407fbea43cfa58d206650c167f340afc15 /src | |
parent | b410773b502abfcd8cc225fe4cd36d84108c0aeb (diff) | |
download | binaryen-0f9339d4e9cfce796d5056c962a183680a19c8ea.tar.gz binaryen-0f9339d4e9cfce796d5056c962a183680a19c8ea.tar.bz2 binaryen-0f9339d4e9cfce796d5056c962a183680a19c8ea.zip |
ir/bits.h cleanups after #2879 (#3156)
Improve some comments, and remove fast paths that are just optimizations for
compile time (code clarity matters more here).
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/bits.h | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/src/ir/bits.h b/src/ir/bits.h index 4a20e5753..40bd8e545 100644 --- a/src/ir/bits.h +++ b/src/ir/bits.h @@ -176,7 +176,7 @@ Index getMaxBits(Expression* curr, case RemSInt32: { if (auto* c = binary->right->dynCast<Const>()) { auto maxBitsLeft = getMaxBits(binary->left, localInfoProvider); - // if maxBitsLeft is negative + // if left may be negative, the result may be negative if (maxBitsLeft == 32) { return 32; } @@ -199,12 +199,8 @@ Index getMaxBits(Expression* curr, } case OrInt32: case XorInt32: { - auto maxBits = getMaxBits(binary->right, localInfoProvider); - // if maxBits is negative - if (maxBits == 32) { - return 32; - } - return std::max(getMaxBits(binary->left, localInfoProvider), maxBits); + return std::max(getMaxBits(binary->left, localInfoProvider), + getMaxBits(binary->right, localInfoProvider)); } case ShlInt32: { if (auto* shifts = binary->right->dynCast<Const>()) { @@ -227,7 +223,7 @@ Index getMaxBits(Expression* curr, case ShrSInt32: { if (auto* shift = binary->right->dynCast<Const>()) { auto maxBits = getMaxBits(binary->left, localInfoProvider); - // if maxBits is negative + // if left may be negative, the result may be negative if (maxBits == 32) { return 32; } @@ -255,7 +251,7 @@ Index getMaxBits(Expression* curr, case DivSInt64: { if (auto* c = binary->right->dynCast<Const>()) { int32_t maxBitsLeft = getMaxBits(binary->left, localInfoProvider); - // if maxBitsLeft or right const value is negative + // if left or right const value is negative if (maxBitsLeft == 64 || c->value.geti64() < 0) { return 64; } @@ -275,7 +271,7 @@ Index getMaxBits(Expression* curr, case RemSInt64: { if (auto* c = binary->right->dynCast<Const>()) { auto maxBitsLeft = getMaxBits(binary->left, localInfoProvider); - // if maxBitsLeft is negative + // if left may be negative, the result may be negative if (maxBitsLeft == 64) { return 64; } @@ -293,17 +289,13 @@ Index getMaxBits(Expression* curr, return 64; } case AndInt64: { - auto maxBits = getMaxBits(binary->right, localInfoProvider); - return std::min(getMaxBits(binary->left, localInfoProvider), maxBits); + return std::min(getMaxBits(binary->left, localInfoProvider), + getMaxBits(binary->right, localInfoProvider)); } case OrInt64: case XorInt64: { - auto maxBits = getMaxBits(binary->right, localInfoProvider); - // if maxBits is negative - if (maxBits == 64) { - return 64; - } - return std::max(getMaxBits(binary->left, localInfoProvider), maxBits); + return std::max(getMaxBits(binary->left, localInfoProvider), + getMaxBits(binary->right, localInfoProvider)); } case ShlInt64: { if (auto* shifts = binary->right->dynCast<Const>()) { @@ -326,7 +318,7 @@ Index getMaxBits(Expression* curr, case ShrSInt64: { if (auto* shift = binary->right->dynCast<Const>()) { auto maxBits = getMaxBits(binary->left, localInfoProvider); - // if maxBits is negative + // if left may be negative, the result may be negative if (maxBits == 64) { return 64; } |