Merge pull request #8707 from ethereum/optimizeIdempotencies

Rules for optimizing idempotency for bitwise operations.
This commit is contained in:
chriseth 2020-04-23 14:42:32 +02:00 committed by GitHub
commit aa071af476
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 0 deletions

View File

@ -6,6 +6,7 @@ Language Features:
Compiler Features:
* Optimizer: Simplify repeated AND and OR operations.
Bugfixes:
* SMTChecker: Fix internal error when fixed points are used.

View File

@ -232,6 +232,28 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleListPart4(
};
}
template <class Pattern>
std::vector<SimplificationRule<Pattern>> simplificationRuleListPart4_5(
Pattern,
Pattern,
Pattern,
Pattern X,
Pattern Y
)
{
using Builtins = typename Pattern::Builtins;
return std::vector<SimplificationRule<Pattern>>{
// idempotent operations
{Builtins::AND(Builtins::AND(X, Y), Y), [=]{ return Builtins::AND(X, Y); }, true},
{Builtins::AND(Y, Builtins::AND(X, Y)), [=]{ return Builtins::AND(X, Y); }, true},
{Builtins::AND(Builtins::AND(Y, X), Y), [=]{ return Builtins::AND(Y, X); }, true},
{Builtins::AND(Y, Builtins::AND(Y, X)), [=]{ return Builtins::AND(Y, X); }, true},
{Builtins::OR(Builtins::OR(X, Y), Y), [=]{ return Builtins::OR(X, Y); }, true},
{Builtins::OR(Y, Builtins::OR(X, Y)), [=]{ return Builtins::OR(X, Y); }, true},
{Builtins::OR(Builtins::OR(Y, X), Y), [=]{ return Builtins::OR(Y, X); }, true},
{Builtins::OR(Y, Builtins::OR(Y, X)), [=]{ return Builtins::OR(Y, X); }, true},
};
}
template <class Pattern>
std::vector<SimplificationRule<Pattern>> simplificationRuleListPart5(
@ -663,6 +685,7 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleList(
rules += simplificationRuleListPart2(A, B, C, W, X);
rules += simplificationRuleListPart3(A, B, C, W, X);
rules += simplificationRuleListPart4(A, B, C, W, X);
rules += simplificationRuleListPart4_5(A, B, C, W, X);
rules += simplificationRuleListPart5(A, B, C, W, X);
rules += simplificationRuleListPart6(A, B, C, W, X);
rules += simplificationRuleListPart7(A, B, C, W, X);

View File

@ -0,0 +1,15 @@
{
let x := calldataload(0)
let z := calldataload(1)
let t := and(and(x, z), x)
let w := or(or(x, z), x)
}
// ----
// step: expressionSimplifier
//
// {
// let x := calldataload(0)
// let z := calldataload(1)
// let t := and(x, z)
// let w := or(x, z)
// }