aboutsummaryrefslogtreecommitdiffstats
path: root/libevmasm
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2018-04-04 21:28:15 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-04-04 23:47:58 +0800
commit02ea0e547f3faa687f9c986ca9a0201b995846c0 (patch)
treee6ab87291d5e0738c3bb2089464a75868567bb64 /libevmasm
parentefa0ccaf9e25a257e1ee6b36c0b77b1532131077 (diff)
downloaddexon-solidity-02ea0e547f3faa687f9c986ca9a0201b995846c0.tar
dexon-solidity-02ea0e547f3faa687f9c986ca9a0201b995846c0.tar.gz
dexon-solidity-02ea0e547f3faa687f9c986ca9a0201b995846c0.tar.bz2
dexon-solidity-02ea0e547f3faa687f9c986ca9a0201b995846c0.tar.lz
dexon-solidity-02ea0e547f3faa687f9c986ca9a0201b995846c0.tar.xz
dexon-solidity-02ea0e547f3faa687f9c986ca9a0201b995846c0.tar.zst
dexon-solidity-02ea0e547f3faa687f9c986ca9a0201b995846c0.zip
Replace comparison operators with opposites if preceded by SWAP1
Diffstat (limited to 'libevmasm')
-rw-r--r--libevmasm/PeepholeOptimiser.cpp28
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) ||