diff options
author | chriseth <chris@ethereum.org> | 2018-06-20 17:38:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-20 17:38:37 +0800 |
commit | ba7fbf11e72a4f9da149ac3c9b4c908e4f215250 (patch) | |
tree | 0321ccecdd76aa4a17bfc1614cf1ae1ad50e0f13 /libevmasm/PeepholeOptimiser.cpp | |
parent | c9ff67ca3e55ba46f6cb4332158328db0c1d2660 (diff) | |
parent | 804eb3ef9d45cd9e4f57ba9b4bd60fea36135ca2 (diff) | |
download | dexon-solidity-ba7fbf11e72a4f9da149ac3c9b4c908e4f215250.tar dexon-solidity-ba7fbf11e72a4f9da149ac3c9b4c908e4f215250.tar.gz dexon-solidity-ba7fbf11e72a4f9da149ac3c9b4c908e4f215250.tar.bz2 dexon-solidity-ba7fbf11e72a4f9da149ac3c9b4c908e4f215250.tar.lz dexon-solidity-ba7fbf11e72a4f9da149ac3c9b4c908e4f215250.tar.xz dexon-solidity-ba7fbf11e72a4f9da149ac3c9b4c908e4f215250.tar.zst dexon-solidity-ba7fbf11e72a4f9da149ac3c9b4c908e4f215250.zip |
Merge pull request #4300 from nventuro/optimize-out-and
Add TruthyAnd Peephole optimization
Diffstat (limited to 'libevmasm/PeepholeOptimiser.cpp')
-rw-r--r-- | libevmasm/PeepholeOptimiser.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/libevmasm/PeepholeOptimiser.cpp b/libevmasm/PeepholeOptimiser.cpp index 8a39de24..6d8e1df6 100644 --- a/libevmasm/PeepholeOptimiser.cpp +++ b/libevmasm/PeepholeOptimiser.cpp @@ -249,6 +249,23 @@ struct TagConjunctions: SimplePeepholeOptimizerMethod<TagConjunctions, 3> } }; +struct TruthyAnd: SimplePeepholeOptimizerMethod<TruthyAnd, 3> +{ + static bool applySimple( + AssemblyItem const& _push, + AssemblyItem const& _not, + AssemblyItem const& _and, + std::back_insert_iterator<AssemblyItems> + ) + { + return ( + _push.type() == Push && _push.data() == 0 && + _not == Instruction::NOT && + _and == Instruction::AND + ); + } +}; + /// Removes everything after a JUMP (or similar) until the next JUMPDEST. struct UnreachableCode { @@ -305,7 +322,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(), SwapComparison(), JumpToNext(), UnreachableCode(), TagConjunctions(), Identity()); + applyMethods(state, PushPop(), OpPop(), DoublePush(), DoubleSwap(), CommutativeSwap(), SwapComparison(), JumpToNext(), UnreachableCode(), TagConjunctions(), TruthyAnd(), Identity()); if (m_optimisedItems.size() < m_items.size() || ( m_optimisedItems.size() == m_items.size() && ( eth::bytesRequired(m_optimisedItems, 3) < eth::bytesRequired(m_items, 3) || |