diff options
Diffstat (limited to 'src')
-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))) && |