diff options
author | chriseth <chris@ethereum.org> | 2018-04-05 17:57:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-05 17:57:26 +0800 |
commit | c6da5c1650964f9dadd4b483d42585223e086b74 (patch) | |
tree | 693cc1ec510c7eb688eb0fc0e31cc97380c1e265 /libevmasm/PeepholeOptimiser.cpp | |
parent | c6adad9368dce6b02d924b0fd3afb4bba4b23c06 (diff) | |
parent | 8dc9113e370a2edd42213c2c0cca811a3dbd8dd4 (diff) | |
download | dexon-solidity-c6da5c1650964f9dadd4b483d42585223e086b74.tar dexon-solidity-c6da5c1650964f9dadd4b483d42585223e086b74.tar.gz dexon-solidity-c6da5c1650964f9dadd4b483d42585223e086b74.tar.bz2 dexon-solidity-c6da5c1650964f9dadd4b483d42585223e086b74.tar.lz dexon-solidity-c6da5c1650964f9dadd4b483d42585223e086b74.tar.xz dexon-solidity-c6da5c1650964f9dadd4b483d42585223e086b74.tar.zst dexon-solidity-c6da5c1650964f9dadd4b483d42585223e086b74.zip |
Merge pull request #3822 from ethereum/swap-comparison
Replace comparison operators with opposites if preceded by SWAP1
Diffstat (limited to 'libevmasm/PeepholeOptimiser.cpp')
-rw-r--r-- | libevmasm/PeepholeOptimiser.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/libevmasm/PeepholeOptimiser.cpp b/libevmasm/PeepholeOptimiser.cpp index 30646545..8a39de24 100644 --- a/libevmasm/PeepholeOptimiser.cpp +++ b/libevmasm/PeepholeOptimiser.cpp @@ -173,6 +173,32 @@ struct CommutativeSwap: SimplePeepholeOptimizerMethod<CommutativeSwap, 2> } }; +struct SwapComparison: SimplePeepholeOptimizerMethod<SwapComparison, 2> +{ + static bool applySimple(AssemblyItem const& _swap, AssemblyItem const& _op, std::back_insert_iterator<AssemblyItems> _out) + { + map<Instruction, Instruction> swappableOps{ + { Instruction::LT, Instruction::GT }, + { Instruction::GT, Instruction::LT }, + { Instruction::SLT, Instruction::SGT }, + { Instruction::SGT, Instruction::SLT } + }; + + if ( + _swap.type() == Operation && + _swap.instruction() == Instruction::SWAP1 && + _op.type() == Operation && + swappableOps.count(_op.instruction()) + ) + { + *_out = swappableOps.at(_op.instruction()); + return true; + } + else + return false; + } +}; + struct JumpToNext: SimplePeepholeOptimizerMethod<JumpToNext, 3> { static size_t applySimple( @@ -279,7 +305,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(), CommutativeSwap(), JumpToNext(), UnreachableCode(), TagConjunctions(), Identity()); + applyMethods(state, PushPop(), OpPop(), DoublePush(), DoubleSwap(), CommutativeSwap(), SwapComparison(), 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) || |