Skip to content

Commit

Permalink
Merge pull request #6756 from ethereum/shiftMulRules
Browse files Browse the repository at this point in the history
Add optimizer rules for multiplication and division by left-shifted one.
  • Loading branch information
chriseth authored May 15, 2019
2 parents a10501b + a5427bc commit ca4b1bc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Compiler Features:
* SMTChecker: Inline external function calls to ``this``.
* Assembler: Encode the compiler version in the deployed bytecode.
* Yul Optimizer: Simplify single-run ``for`` loops to ``if`` statements.
* Optimizer: Add rules for multiplication and division by left-shifted one.


Bugfixes:
Expand Down
25 changes: 25 additions & 0 deletions libevmasm/RuleList.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,31 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleListPart7(
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 = [=]() {
if (B.d() > 256)
Expand Down

0 comments on commit ca4b1bc

Please sign in to comment.