diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2018-04-04 14:15:24 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-04 14:15:24 +0800 |
commit | 920de496ab1d403f06640c17c9999c5024730f8f (patch) | |
tree | cbdb329b73a1c2c16834325fd008b375b3e13361 /libevmasm/PeepholeOptimiser.cpp | |
parent | 0695ffe51d5195dbedce37b26bbe395cfdaf3746 (diff) | |
parent | be6051beadcc54705f35738d37af017d654c2c01 (diff) | |
download | dexon-solidity-920de496ab1d403f06640c17c9999c5024730f8f.tar dexon-solidity-920de496ab1d403f06640c17c9999c5024730f8f.tar.gz dexon-solidity-920de496ab1d403f06640c17c9999c5024730f8f.tar.bz2 dexon-solidity-920de496ab1d403f06640c17c9999c5024730f8f.tar.lz dexon-solidity-920de496ab1d403f06640c17c9999c5024730f8f.tar.xz dexon-solidity-920de496ab1d403f06640c17c9999c5024730f8f.tar.zst dexon-solidity-920de496ab1d403f06640c17c9999c5024730f8f.zip |
Merge pull request #3798 from ethereum/commutative-swap
Remove useless SWAP1 in front of commutative operations
Diffstat (limited to 'libevmasm/PeepholeOptimiser.cpp')
-rw-r--r-- | libevmasm/PeepholeOptimiser.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/libevmasm/PeepholeOptimiser.cpp b/libevmasm/PeepholeOptimiser.cpp index 168d1109..30646545 100644 --- a/libevmasm/PeepholeOptimiser.cpp +++ b/libevmasm/PeepholeOptimiser.cpp @@ -154,6 +154,25 @@ struct DoublePush: SimplePeepholeOptimizerMethod<DoublePush, 2> } }; +struct CommutativeSwap: SimplePeepholeOptimizerMethod<CommutativeSwap, 2> +{ + static bool applySimple(AssemblyItem const& _swap, AssemblyItem const& _op, std::back_insert_iterator<AssemblyItems> _out) + { + // Remove SWAP1 if following instruction is commutative + if ( + _swap.type() == Operation && + _swap.instruction() == Instruction::SWAP1 && + SemanticInformation::isCommutativeOperation(_op) + ) + { + *_out = _op; + return true; + } + else + return false; + } +}; + struct JumpToNext: SimplePeepholeOptimizerMethod<JumpToNext, 3> { static size_t applySimple( @@ -260,7 +279,7 @@ bool PeepholeOptimiser::optimise() { OptimiserState state {m_items, 0, std::back_inserter(m_optimisedItems)}; while (state.i < m_items.size()) - applyMethods(state, PushPop(), OpPop(), DoublePush(), DoubleSwap(), JumpToNext(), UnreachableCode(), TagConjunctions(), Identity()); + applyMethods(state, PushPop(), OpPop(), DoublePush(), DoubleSwap(), CommutativeSwap(), 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) || |