From 7aa2ee177546399343b4e79fb0efbf0353395be3 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 26 Feb 2019 12:12:46 +0000 Subject: [PATCH] More optimiser rules for LT/GT/AND/BYTE --- Changelog.md | 1 + libevmasm/RuleList.h | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 753e4dfb2..ea766f70b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -10,6 +10,7 @@ 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: Support shifts in the constant optimiser for Constantinople. diff --git a/libevmasm/RuleList.h b/libevmasm/RuleList.h index 7cdf5a96f..7ec3ca461 100644 --- a/libevmasm/RuleList.h +++ b/libevmasm/RuleList.h @@ -108,7 +108,7 @@ std::vector> simplificationRuleListPart2( Pattern, Pattern, Pattern X, - Pattern + Pattern Y ) { return std::vector> { @@ -146,6 +146,12 @@ std::vector> 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} }; }