diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 4c4adc623..181e8285e 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -1148,17 +1148,20 @@ private: } } } - // note that this is correct even on floats with a NaN on the left, - // as a NaN would skip the computation and just return the NaN, - // and that is precisely what we do here. but, the same with -1 - // (change to a negation) would be incorrect for that reason. - if (right->value == Literal::makeFromInt32(1, type)) { - if (binary->op == Abstract::getBinary(type, Abstract::Mul) || - binary->op == Abstract::getBinary(type, Abstract::DivS) || - binary->op == Abstract::getBinary(type, Abstract::DivU)) { - return binary->left; + if (isIntegerType(type) || isFloatType(type)) { + // note that this is correct even on floats with a NaN on the left, + // as a NaN would skip the computation and just return the NaN, + // and that is precisely what we do here. but, the same with -1 + // (change to a negation) would be incorrect for that reason. + if (right->value == Literal::makeFromInt32(1, type)) { + if (binary->op == Abstract::getBinary(type, Abstract::Mul) || + binary->op == Abstract::getBinary(type, Abstract::DivS) || + binary->op == Abstract::getBinary(type, Abstract::DivU)) { + return binary->left; + } } } + // TODO: v128 not implemented yet return nullptr; } @@ -1191,9 +1194,9 @@ private: // x + 5 == 7 // => // x == 2 - if (binary->op == Abstract::getBinary(type, Abstract::Eq) || - binary->op == Abstract::getBinary(type, Abstract::Ne)) { - if (isIntegerType(binary->left->type)) { + if (isIntegerType(binary->left->type)) { + if (binary->op == Abstract::getBinary(type, Abstract::Eq) || + binary->op == Abstract::getBinary(type, Abstract::Ne)) { if (auto* left = binary->left->dynCast<Binary>()) { if (left->op == Abstract::getBinary(type, Abstract::Add) || left->op == Abstract::getBinary(type, Abstract::Sub)) { |