diff options
author | Max Graey <maxgraey@gmail.com> | 2020-10-28 00:42:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-27 15:42:05 -0700 |
commit | 5c31f461afe87088e1e0972dbcbf0507c15b2880 (patch) | |
tree | e7ca96cd38a3ae24fa1f3ad36d206d1589bd62fb /src/passes/OptimizeInstructions.cpp | |
parent | c015eebaee6161112eb82b1faa892c864ddffa27 (diff) | |
download | binaryen-5c31f461afe87088e1e0972dbcbf0507c15b2880.tar.gz binaryen-5c31f461afe87088e1e0972dbcbf0507c15b2880.tar.bz2 binaryen-5c31f461afe87088e1e0972dbcbf0507c15b2880.zip |
Replace x * 2 with x + x for floats (#3016)
But only when doing so doesn't require adding a new local.
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index b11df3276..89315ab60 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -1664,6 +1664,19 @@ private: } } { + // x * 2.0 ==> x + x + // but we apply this only for simple expressions like + // local.get and global.get for avoid using extra local + // variable. + Expression* x; + if (matches(curr, binary(Mul, any(&x), fval(2.0))) && + (x->is<LocalGet>() || x->is<GlobalGet>())) { + curr->op = Abstract::getBinary(type, Abstract::Add); + curr->right = ExpressionManipulator::copy(x, *getModule()); + return curr; + } + } + { // x + (-0.0) ==> x double value; if (fastMath && matches(curr, binary(Add, any(), fval(&value))) && |