@@ -1148,17 +1148,20 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions,
11481148 }
11491149 }
11501150 }
1151- // note that this is correct even on floats with a NaN on the left,
1152- // as a NaN would skip the computation and just return the NaN,
1153- // and that is precisely what we do here. but, the same with -1
1154- // (change to a negation) would be incorrect for that reason.
1155- if (right->value == Literal::makeFromInt32 (1 , type)) {
1156- if (binary->op == Abstract::getBinary (type, Abstract::Mul) ||
1157- binary->op == Abstract::getBinary (type, Abstract::DivS) ||
1158- binary->op == Abstract::getBinary (type, Abstract::DivU)) {
1159- return binary->left ;
1151+ if (isIntegerType (type) || isFloatType (type)) {
1152+ // note that this is correct even on floats with a NaN on the left,
1153+ // as a NaN would skip the computation and just return the NaN,
1154+ // and that is precisely what we do here. but, the same with -1
1155+ // (change to a negation) would be incorrect for that reason.
1156+ if (right->value == Literal::makeFromInt32 (1 , type)) {
1157+ if (binary->op == Abstract::getBinary (type, Abstract::Mul) ||
1158+ binary->op == Abstract::getBinary (type, Abstract::DivS) ||
1159+ binary->op == Abstract::getBinary (type, Abstract::DivU)) {
1160+ return binary->left ;
1161+ }
11601162 }
11611163 }
1164+ // TODO: v128 not implemented yet
11621165 return nullptr ;
11631166 }
11641167
@@ -1191,9 +1194,9 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions,
11911194 // x + 5 == 7
11921195 // =>
11931196 // x == 2
1194- if (binary->op == Abstract::getBinary ( type, Abstract::Eq) ||
1195- binary->op == Abstract::getBinary (type, Abstract::Ne)) {
1196- if ( isIntegerType ( binary->left -> type )) {
1197+ if (isIntegerType ( binary->left -> type )) {
1198+ if ( binary->op == Abstract::getBinary (type, Abstract::Eq) ||
1199+ binary->op == Abstract::getBinary ( type, Abstract::Ne )) {
11971200 if (auto * left = binary->left ->dynCast <Binary>()) {
11981201 if (left->op == Abstract::getBinary (type, Abstract::Add) ||
11991202 left->op == Abstract::getBinary (type, Abstract::Sub)) {
0 commit comments