aboutsummaryrefslogtreecommitdiffstats
path: root/test/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 /test/libevmasm
parentefa0ccaf9e25a257e1ee6b36c0b77b1532131077 (diff)
downloaddexon-solidity-02ea0e547f3faa687f9c986ca9a0201b995846c0.tar.gz
dexon-solidity-02ea0e547f3faa687f9c986ca9a0201b995846c0.tar.zst
dexon-solidity-02ea0e547f3faa687f9c986ca9a0201b995846c0.zip
Replace comparison operators with opposites if preceded by SWAP1
Diffstat (limited to 'test/libevmasm')
-rw-r--r--test/libevmasm/Optimiser.cpp43
1 files changed, 38 insertions, 5 deletions
diff --git a/test/libevmasm/Optimiser.cpp b/test/libevmasm/Optimiser.cpp
index b622b4fb..089be45d 100644
--- a/test/libevmasm/Optimiser.cpp
+++ b/test/libevmasm/Optimiser.cpp
@@ -888,7 +888,7 @@ BOOST_AUTO_TEST_CASE(peephole_commutative_swap1)
PeepholeOptimiser peepOpt(items);
BOOST_REQUIRE(peepOpt.optimise());
BOOST_CHECK_EQUAL_COLLECTIONS(
- items.begin(), items.end(),
+ items.begin(), items.end(),
expectation.begin(), expectation.end()
);
}
@@ -903,9 +903,7 @@ BOOST_AUTO_TEST_CASE(peephole_noncommutative_swap1)
Instruction::SDIV,
Instruction::MOD,
Instruction::SMOD,
- Instruction::EXP,
- Instruction::LT,
- Instruction::GT
+ Instruction::EXP
};
for (Instruction const op: ops)
{
@@ -928,7 +926,42 @@ BOOST_AUTO_TEST_CASE(peephole_noncommutative_swap1)
PeepholeOptimiser peepOpt(items);
BOOST_REQUIRE(!peepOpt.optimise());
BOOST_CHECK_EQUAL_COLLECTIONS(
- items.begin(), items.end(),
+ items.begin(), items.end(),
+ expectation.begin(), expectation.end()
+ );
+ }
+}
+
+BOOST_AUTO_TEST_CASE(peephole_swap_comparison)
+{
+ map<Instruction, Instruction> swappableOps{
+ { Instruction::LT, Instruction::GT },
+ { Instruction::GT, Instruction::LT },
+ { Instruction::SLT, Instruction::SGT },
+ { Instruction::SGT, Instruction::SLT }
+ };
+
+ for (auto const& op: swappableOps)
+ {
+ AssemblyItems items{
+ u256(1),
+ u256(2),
+ Instruction::SWAP1,
+ op.first,
+ u256(4),
+ u256(5)
+ };
+ AssemblyItems expectation{
+ u256(1),
+ u256(2),
+ op.second,
+ u256(4),
+ u256(5)
+ };
+ PeepholeOptimiser peepOpt(items);
+ BOOST_REQUIRE(peepOpt.optimise());
+ BOOST_CHECK_EQUAL_COLLECTIONS(
+ items.begin(), items.end(),
expectation.begin(), expectation.end()
);
}