aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2018-04-04 00:05:06 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-04-04 00:57:28 +0800
commitbe6051beadcc54705f35738d37af017d654c2c01 (patch)
tree8069f6e10e695c70e1b5649893bdde6d1bf6c749
parent17bcabb6cfb42a3983ecb79768d44622507ce292 (diff)
downloaddexon-solidity-be6051beadcc54705f35738d37af017d654c2c01.tar.gz
dexon-solidity-be6051beadcc54705f35738d37af017d654c2c01.tar.zst
dexon-solidity-be6051beadcc54705f35738d37af017d654c2c01.zip
Test multiple instructions with the (non)commutative peephole optimiser
-rw-r--r--test/libevmasm/Optimiser.cpp99
1 files changed, 62 insertions, 37 deletions
diff --git a/test/libevmasm/Optimiser.cpp b/test/libevmasm/Optimiser.cpp
index 6b588e75..b622b4fb 100644
--- a/test/libevmasm/Optimiser.cpp
+++ b/test/libevmasm/Optimiser.cpp
@@ -860,53 +860,78 @@ BOOST_AUTO_TEST_CASE(peephole_pop_calldatasize)
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),
+ vector<Instruction> ops{
Instruction::ADD,
- u256(4),
- u256(5)
+ Instruction::MUL,
+ Instruction::EQ,
+ Instruction::AND,
+ Instruction::OR,
+ Instruction::XOR
};
- PeepholeOptimiser peepOpt(items);
- BOOST_REQUIRE(peepOpt.optimise());
- BOOST_CHECK_EQUAL_COLLECTIONS(
+ for (Instruction const op: ops)
+ {
+ AssemblyItems items{
+ u256(1),
+ u256(2),
+ Instruction::SWAP1,
+ op,
+ u256(4),
+ u256(5)
+ };
+ AssemblyItems expectation{
+ u256(1),
+ u256(2),
+ op,
+ u256(4),
+ u256(5)
+ };
+ PeepholeOptimiser peepOpt(items);
+ BOOST_REQUIRE(peepOpt.optimise());
+ BOOST_CHECK_EQUAL_COLLECTIONS(
items.begin(), items.end(),
- expectation.begin(), expectation.end()
- );
+ expectation.begin(), expectation.end()
+ );
+ }
}
BOOST_AUTO_TEST_CASE(peephole_noncommutative_swap1)
{
- AssemblyItems items{
- u256(1),
- u256(2),
- Instruction::SWAP1,
+ // NOTE: not comprehensive
+ vector<Instruction> ops{
Instruction::SUB,
- u256(4),
- u256(5)
- };
- AssemblyItems expectation{
- u256(1),
- u256(2),
- Instruction::SWAP1,
- Instruction::SUB,
- u256(4),
- u256(5)
+ Instruction::DIV,
+ Instruction::SDIV,
+ Instruction::MOD,
+ Instruction::SMOD,
+ Instruction::EXP,
+ Instruction::LT,
+ Instruction::GT
};
- PeepholeOptimiser peepOpt(items);
- BOOST_REQUIRE(!peepOpt.optimise());
- BOOST_CHECK_EQUAL_COLLECTIONS(
+ for (Instruction const op: ops)
+ {
+ AssemblyItems items{
+ u256(1),
+ u256(2),
+ Instruction::SWAP1,
+ op,
+ u256(4),
+ u256(5)
+ };
+ AssemblyItems expectation{
+ u256(1),
+ u256(2),
+ Instruction::SWAP1,
+ op,
+ u256(4),
+ u256(5)
+ };
+ PeepholeOptimiser peepOpt(items);
+ BOOST_REQUIRE(!peepOpt.optimise());
+ BOOST_CHECK_EQUAL_COLLECTIONS(
items.begin(), items.end(),
- expectation.begin(), expectation.end()
- );
+ expectation.begin(), expectation.end()
+ );
+ }
}
BOOST_AUTO_TEST_CASE(jumpdest_removal)