Add optimizer rules for multiplication and division by left-shifted one.

This commit is contained in:
Daniel Kirchner 2019-05-14 16:01:50 +02:00
parent 74fbf5402d
commit a5427bc63a
2 changed files with 26 additions and 0 deletions

View File

@ -11,6 +11,7 @@ Compiler Features:
* SMTChecker: Inline external function calls to ``this``. * SMTChecker: Inline external function calls to ``this``.
* Assembler: Encode the compiler version in the deployed bytecode. * Assembler: Encode the compiler version in the deployed bytecode.
* Yul Optimizer: Simplify single-run ``for`` loops to ``if`` statements. * Yul Optimizer: Simplify single-run ``for`` loops to ``if`` statements.
* Optimizer: Add rules for multiplication and division by left-shifted one.
Bugfixes: Bugfixes:

View File

@ -391,6 +391,31 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleListPart7(
false false
}); });
rules.push_back({
// MUL(X, SHL(Y, 1)) -> SHL(Y, X)
{Instruction::MUL, {X, {Instruction::SHL, {Y, u256(1)}}}},
[=]() -> Pattern {
return {Instruction::SHL, {Y, X}};
},
false
});
rules.push_back({
// MUL(SHL(X, 1), Y) -> SHL(X, Y)
{Instruction::MUL, {{Instruction::SHL, {X, u256(1)}}, Y}},
[=]() -> Pattern {
return {Instruction::SHL, {X, Y}};
},
false
});
rules.push_back({
// DIV(X, SHL(Y, 1)) -> SHR(Y, X)
{Instruction::DIV, {X, {Instruction::SHL, {Y, u256(1)}}}},
[=]() -> Pattern {
return {Instruction::SHR, {Y, X}};
},
false
});
std::function<bool()> feasibilityFunction = [=]() { std::function<bool()> feasibilityFunction = [=]() {
if (B.d() > 256) if (B.d() > 256)