mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Combine multiple shifts with constant shift-by values in the optimiser
This commit is contained in:
parent
58236c8457
commit
4430fe6a54
@ -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.
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user