summaryrefslogtreecommitdiff
path: root/src/passes/OptimizeInstructions.cpp
diff options
context:
space:
mode:
authorMax Graey <maxgraey@gmail.com>2020-10-20 22:35:36 +0300
committerGitHub <noreply@github.com>2020-10-20 12:35:36 -0700
commit8b31756134ba4460d1dc5320198a87f88af2443c (patch)
tree2b675ce14dc02a6801b4b6cedb2cec617d7806bc /src/passes/OptimizeInstructions.cpp
parentc0c3812dfde2b8086b2fdd603e0d70705ec8a1e4 (diff)
downloadbinaryen-8b31756134ba4460d1dc5320198a87f88af2443c.tar.gz
binaryen-8b31756134ba4460d1dc5320198a87f88af2443c.tar.bz2
binaryen-8b31756134ba4460d1dc5320198a87f88af2443c.zip
Optimize signed division when RHS is signed minimum (#3221)
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r--src/passes/OptimizeInstructions.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index 2736c8984..232faab7a 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -1454,6 +1454,23 @@ private:
right->value = Literal::makeZero(type);
return right;
}
+ // i32(x) / i32.min_s ==> x == i32.min_s
+ if (matches(
+ curr,
+ binary(DivSInt32, any(), i32(std::numeric_limits<int32_t>::min())))) {
+ curr->op = EqInt32;
+ return curr;
+ }
+ // i64(x) / i64.min_s ==> i64(x == i64.min_s)
+ // only for zero shrink level
+ if (getPassOptions().shrinkLevel == 0 &&
+ matches(
+ curr,
+ binary(DivSInt64, any(), i64(std::numeric_limits<int64_t>::min())))) {
+ curr->op = EqInt64;
+ curr->type = Type::i32;
+ return Builder(*getModule()).makeUnary(ExtendUInt32, curr);
+ }
// (unsigned)x > -1 ==> 0
if (matches(curr, binary(Abstract::GtU, pure(&left), ival(-1)))) {
right->value = Literal::makeZero(Type::i32);