aboutsummaryrefslogtreecommitdiffstats
path: root/test/libevmasm
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2018-03-29 19:10:39 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-04-04 00:57:07 +0800
commit17bcabb6cfb42a3983ecb79768d44622507ce292 (patch)
tree38a461706217087ba3253282c5309a40e692a052 /test/libevmasm
parent0edce4b570c157927933697b30f0f94cbdf173b2 (diff)
downloaddexon-solidity-17bcabb6cfb42a3983ecb79768d44622507ce292.tar.gz
dexon-solidity-17bcabb6cfb42a3983ecb79768d44622507ce292.tar.zst
dexon-solidity-17bcabb6cfb42a3983ecb79768d44622507ce292.zip
Remove useless SWAP1 in front of commutative operations
Diffstat (limited to 'test/libevmasm')
-rw-r--r--test/libevmasm/Optimiser.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/libevmasm/Optimiser.cpp b/test/libevmasm/Optimiser.cpp
index 28f6b8c0..6b588e75 100644
--- a/test/libevmasm/Optimiser.cpp
+++ b/test/libevmasm/Optimiser.cpp
@@ -858,6 +858,57 @@ BOOST_AUTO_TEST_CASE(peephole_pop_calldatasize)
BOOST_CHECK(items.empty());
}
+BOOST_AUTO_TEST_CASE(peephole_commutative_swap1)
+{
+ AssemblyItems items{
+ u256(1),
+ u256(2),
+ Instruction::SWAP1,
+ Instruction::ADD,
+ u256(4),
+ u256(5)
+ };
+ AssemblyItems expectation{
+ u256(1),
+ u256(2),
+ Instruction::ADD,
+ u256(4),
+ u256(5)
+ };
+ PeepholeOptimiser peepOpt(items);
+ BOOST_REQUIRE(peepOpt.optimise());
+ BOOST_CHECK_EQUAL_COLLECTIONS(
+ items.begin(), items.end(),
+ expectation.begin(), expectation.end()
+ );
+}
+
+BOOST_AUTO_TEST_CASE(peephole_noncommutative_swap1)
+{
+ AssemblyItems items{
+ u256(1),
+ u256(2),
+ Instruction::SWAP1,
+ Instruction::SUB,
+ u256(4),
+ u256(5)
+ };
+ AssemblyItems expectation{
+ u256(1),
+ u256(2),
+ Instruction::SWAP1,
+ Instruction::SUB,
+ u256(4),
+ u256(5)
+ };
+ PeepholeOptimiser peepOpt(items);
+ BOOST_REQUIRE(!peepOpt.optimise());
+ BOOST_CHECK_EQUAL_COLLECTIONS(
+ items.begin(), items.end(),
+ expectation.begin(), expectation.end()
+ );
+}
+
BOOST_AUTO_TEST_CASE(jumpdest_removal)
{
AssemblyItems items{