diff options
author | Alon Zakai <alonzakai@gmail.com> | 2017-07-28 14:10:25 -0700 |
---|---|---|
committer | Alon Zakai (kripken) <alonzakai@gmail.com> | 2017-07-29 19:18:53 -0700 |
commit | 1de12041904d5571ead6e64b5e51a3e26c8cfce1 (patch) | |
tree | 5deb95d9fbea4c01091a81b87100be72e274c2a1 /src | |
parent | 1d67ab02aeb71b1a250a44161c8fdb3e97b04210 (diff) | |
download | binaryen-1de12041904d5571ead6e64b5e51a3e26c8cfce1.tar.gz binaryen-1de12041904d5571ead6e64b5e51a3e26c8cfce1.tar.bz2 binaryen-1de12041904d5571ead6e64b5e51a3e26c8cfce1.zip |
fix shift computation in getMaxBits - in wasm only the lower 5 bits matter for a 32-bit shift
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 2930fe9c9..43a8faa32 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -195,7 +195,7 @@ Index getMaxBits(Expression* curr, LocalInfoProvider* localInfoProvider) { case ShrUInt32: { if (auto* shift = binary->right->dynCast<Const>()) { auto maxBits = getMaxBits(binary->left, localInfoProvider); - auto shifts = std::min(Index(shift->value.geti32()), maxBits); // can ignore more shifts than zero us out + auto shifts = std::min(Index(shift->value.geti32() & 31), maxBits); // can ignore more shifts than zero us out return std::max(Index(0), maxBits - shifts); } return 32; @@ -204,7 +204,7 @@ Index getMaxBits(Expression* curr, LocalInfoProvider* localInfoProvider) { if (auto* shift = binary->right->dynCast<Const>()) { auto maxBits = getMaxBits(binary->left, localInfoProvider); if (maxBits == 32) return 32; - auto shifts = std::min(Index(shift->value.geti32()), maxBits); // can ignore more shifts than zero us out + auto shifts = std::min(Index(shift->value.geti32() & 31), maxBits); // can ignore more shifts than zero us out return std::max(Index(0), maxBits - shifts); } return 32; |