Combine multiple shifts with constant shift-by values in the optimiser

This commit is contained in:
Alex Beregszaszi 2019-02-19 16:12:28 +00:00
parent 58236c8457
commit 4430fe6a54
2 changed files with 17 additions and 0 deletions

View File

@ -7,6 +7,7 @@ Compiler Features:
* SMTChecker: Do not report underflow/overflow if they always revert. This removes false positives when using ``SafeMath``.
* Static Analyzer: Warn about expressions with custom types when they have no effect.
* Optimizer: Add rule for shifts with constants for Constantinople.
* Optimizer: Combine multiple shifts with constant shift-by values into one.
* Optimizer: Support shifts in the constant optimiser for Constantinople.

View File

@ -24,6 +24,8 @@
#include <vector>
#include <functional>
#include <boost/multiprecision/detail/min_max.hpp>
#include <libevmasm/Instruction.h>
#include <libevmasm/SimplificationRule.h>
@ -336,6 +338,20 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleListPart7(
}
}
rules.push_back({
// SHL(B, SHL(A, X)) -> SHL(min(A+B, 256), X)
{Instruction::SHL, {{B}, {Instruction::SHL, {{A}, {X}}}}},
[=]() -> Pattern { return {Instruction::SHL, {std::min(A.d() + B.d(), u256(256)), X}}; },
false
});
rules.push_back({
// SHR(B, SHR(A, X)) -> SHR(min(A+B, 256), X)
{Instruction::SHR, {{B}, {Instruction::SHR, {{A}, {X}}}}},
[=]() -> Pattern { return {Instruction::SHR, {std::min(A.d() + B.d(), u256(256)), X}}; },
false
});
return rules;
}