diff options
author | Max Graey <maxgraey@gmail.com> | 2020-10-06 22:47:38 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-06 12:47:38 -0700 |
commit | fe56186c48350e7b4b4a2243022da65703a8f1b7 (patch) | |
tree | 4956aa3d37b221060138c7cc792ab6ff8de68899 /src/passes/OptimizeInstructions.cpp | |
parent | 8548101838bb72ca06abb5cbdc033e39c9d970a7 (diff) | |
download | binaryen-fe56186c48350e7b4b4a2243022da65703a8f1b7.tar.gz binaryen-fe56186c48350e7b4b4a2243022da65703a8f1b7.tar.bz2 binaryen-fe56186c48350e7b4b4a2243022da65703a8f1b7.zip |
Revert some changes for #3193 (#3197)
`(signed)x % (i32|i64).min_s ==> (x & (i32|i64).max_s)` is not valid unless compared to zero.
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 3a344ff88..c54960079 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -304,10 +304,14 @@ struct OptimizeInstructions if (matches(curr, unary(Abstract::EqZ, binary(&inner, Abstract::RemS, any(), ival(&c)))) && - !c->value.isSignedMin() && - Bits::isPowerOf2(c->value.abs().getInteger())) { + (c->value.isSignedMin() || + Bits::isPowerOf2(c->value.abs().getInteger()))) { inner->op = Abstract::getBinary(c->type, Abstract::And); - c->value = c->value.abs().sub(Literal::makeFromInt32(1, c->type)); + if (c->value.isSignedMin()) { + c->value = Literal::makeSignedMax(c->type); + } else { + c->value = c->value.abs().sub(Literal::makeFromInt32(1, c->type)); + } return curr; } } @@ -1308,15 +1312,6 @@ private: right->value = Literal::makeSingleZero(type); return right; } - { - // (signed)x % (i32|i64).min_s ==> (x & (i32|i64).max_s) - if (matches(curr, binary(Abstract::RemS, any(&left), ival())) && - right->value.isSignedMin()) { - curr->op = Abstract::getBinary(type, Abstract::And); - right->value = Literal::makeSignedMax(type); - return curr; - } - } // (signed)x % C_pot != 0 ==> (x & (abs(C_pot) - 1)) != 0 { Const* c; @@ -1325,10 +1320,14 @@ private: binary(Abstract::Ne, binary(&inner, Abstract::RemS, any(), ival(&c)), ival(0))) && - !c->value.isSignedMin() && - Bits::isPowerOf2(c->value.abs().getInteger())) { + (c->value.isSignedMin() || + Bits::isPowerOf2(c->value.abs().getInteger()))) { inner->op = Abstract::getBinary(c->type, Abstract::And); - c->value = c->value.abs().sub(Literal::makeFromInt32(1, c->type)); + if (c->value.isSignedMin()) { + c->value = Literal::makeSignedMax(c->type); + } else { + c->value = c->value.abs().sub(Literal::makeFromInt32(1, c->type)); + } return curr; } } |