diff options
Diffstat (limited to 'libevmasm/PeepholeOptimiser.cpp')
-rw-r--r-- | libevmasm/PeepholeOptimiser.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/libevmasm/PeepholeOptimiser.cpp b/libevmasm/PeepholeOptimiser.cpp index 6c92d76b..e94a8ba4 100644 --- a/libevmasm/PeepholeOptimiser.cpp +++ b/libevmasm/PeepholeOptimiser.cpp @@ -136,6 +136,21 @@ struct DoubleSwap: SimplePeepholeOptimizerMethod<DoubleSwap, 2> } }; +struct DoublePush: SimplePeepholeOptimizerMethod<DoublePush, 2> +{ + static bool applySimple(AssemblyItem const& _push1, AssemblyItem const& _push2, std::back_insert_iterator<AssemblyItems> _out) + { + if (_push1.type() == Push && _push2.type() == Push && _push1.data() == _push2.data()) + { + *_out = _push1; + *_out = {Instruction::DUP1, _push2.location()}; + return true; + } + else + return false; + } +}; + struct JumpToNext: SimplePeepholeOptimizerMethod<JumpToNext, 3> { static size_t applySimple( @@ -235,13 +250,15 @@ bool PeepholeOptimiser::optimise() { OptimiserState state {m_items, 0, std::back_inserter(m_optimisedItems)}; while (state.i < m_items.size()) - applyMethods(state, PushPop(), OpPop(), DoubleSwap(), JumpToNext(), UnreachableCode(), TagConjunctions(), Identity()); - if (m_optimisedItems.size() < m_items.size()) + applyMethods(state, PushPop(), OpPop(), DoublePush(), DoubleSwap(), JumpToNext(), UnreachableCode(), TagConjunctions(), Identity()); + if (m_optimisedItems.size() < m_items.size() || ( + m_optimisedItems.size() == m_items.size() && + eth::bytesRequired(m_optimisedItems, 3) < eth::bytesRequired(m_items, 3) + )) { m_items = std::move(m_optimisedItems); return true; } else return false; - } |