Skip to content

Optimize binary operators with equal children even if side effect #7460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Fix
  • Loading branch information
xuruiyang2002 committed Apr 9, 2025
commit e4914943210a55da6e2748de0f0e1ff0848256b2
18 changes: 11 additions & 7 deletions src/passes/OptimizeInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5185,8 +5185,7 @@ struct OptimizeInstructions
case SubInt64:
case XorInt64:
return getDroppedChildrenAndAppend(
binary->left,
LiteralUtils::makeZero(binary->left->type, *getModule()));
binary, LiteralUtils::makeZero(binary->left->type, *getModule()));
case NeInt32:
case LtSInt32:
case LtUInt32:
Expand All @@ -5198,12 +5197,18 @@ struct OptimizeInstructions
case GtSInt64:
case GtUInt64:
return getDroppedChildrenAndAppend(
binary->left, LiteralUtils::makeZero(Type::i32, *getModule()));
binary, LiteralUtils::makeZero(Type::i32, *getModule()));
case AndInt32:
case OrInt32:
case AndInt64:
case OrInt64:
return binary->left;
case OrInt64: {
if (!effects(binary->left).hasSideEffects()) {
if (ExpressionAnalyzer::equal(binary->left, binary->right)) {
return binary->left;
}
}
return binary;
};
case EqInt32:
case LeSInt32:
case LeUInt32:
Expand All @@ -5215,8 +5220,7 @@ struct OptimizeInstructions
case GeSInt64:
case GeUInt64:
return getDroppedChildrenAndAppend(
binary->left,
LiteralUtils::makeFromInt32(1, Type::i32, *getModule()));
binary, LiteralUtils::makeFromInt32(1, Type::i32, *getModule()));
default:
return nullptr;
}
Expand Down