Merge pull request #6159 from ethereum/more-optims

More optimiser rules for LT/GT/AND/BYTE and address cleanups
This commit is contained in:
chriseth 2019-03-04 16:24:38 +01:00 committed by GitHub
commit 34082a2368
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -11,8 +11,10 @@ Compiler Features:
* Inline Assembly: Instructions unavailable to the currently configured EVM are errors now.
* 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 new rules with constants including ``LT``, ``GT``, ``AND`` and ``BYTE``.
* Optimizer: Add rule for shifts with constants for Constantinople.
* Optimizer: Combine multiple shifts with constant shift-by values into one.
* Optimizer: Do not mask with 160-bits after ``CREATE`` and ``CREATE2`` as they are guaranteed to return an address or 0.
* Optimizer: Support shifts in the constant optimiser for Constantinople.
* Yul Optimizer: Add rule to replace switch statements with const expr. with matching case body

View File

@ -108,7 +108,7 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleListPart2(
Pattern,
Pattern,
Pattern X,
Pattern
Pattern Y
)
{
return std::vector<SimplificationRule<Pattern>> {
@ -146,6 +146,12 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleListPart2(
{{Instruction::SHR, {0, X}}, [=]{ return X; }, false},
{{Instruction::SHL, {X, 0}}, [=]{ return u256(0); }, true},
{{Instruction::SHR, {X, 0}}, [=]{ return u256(0); }, true},
{{Instruction::LT, {X, 0}}, [=]{ return u256(0); }, true},
{{Instruction::GT, {X, 0}}, [=]() -> Pattern { return {Instruction::ISZERO, {{Instruction::ISZERO, {X}}}}; }, false},
{{Instruction::GT, {X, ~u256(0)}}, [=]{ return u256(0); }, true},
{{Instruction::GT, {0, X}}, [=]{ return u256(0); }, true},
{{Instruction::AND, {{Instruction::BYTE, {X, Y}}, {u256(0xff)}}}, [=]() -> Pattern { return {Instruction::BYTE, {X, Y}}; }, false},
{{Instruction::BYTE, {X, 31}}, [=]() -> Pattern { return {Instruction::AND, {X, u256(0xff)}}; }, false}
};
}
@ -231,7 +237,9 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleListPart5(
Instruction::ADDRESS,
Instruction::CALLER,
Instruction::ORIGIN,
Instruction::COINBASE
Instruction::COINBASE,
Instruction::CREATE,
Instruction::CREATE2
})
{
u256 const mask = (u256(1) << 160) - 1;