diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2018-04-04 14:15:24 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-04 14:15:24 +0800 |
commit | 920de496ab1d403f06640c17c9999c5024730f8f (patch) | |
tree | cbdb329b73a1c2c16834325fd008b375b3e13361 /test/libevmasm/Optimiser.cpp | |
parent | 0695ffe51d5195dbedce37b26bbe395cfdaf3746 (diff) | |
parent | be6051beadcc54705f35738d37af017d654c2c01 (diff) | |
download | dexon-solidity-920de496ab1d403f06640c17c9999c5024730f8f.tar dexon-solidity-920de496ab1d403f06640c17c9999c5024730f8f.tar.gz dexon-solidity-920de496ab1d403f06640c17c9999c5024730f8f.tar.bz2 dexon-solidity-920de496ab1d403f06640c17c9999c5024730f8f.tar.lz dexon-solidity-920de496ab1d403f06640c17c9999c5024730f8f.tar.xz dexon-solidity-920de496ab1d403f06640c17c9999c5024730f8f.tar.zst dexon-solidity-920de496ab1d403f06640c17c9999c5024730f8f.zip |
Merge pull request #3798 from ethereum/commutative-swap
Remove useless SWAP1 in front of commutative operations
Diffstat (limited to 'test/libevmasm/Optimiser.cpp')
-rw-r--r-- | test/libevmasm/Optimiser.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/test/libevmasm/Optimiser.cpp b/test/libevmasm/Optimiser.cpp index 28f6b8c0..b622b4fb 100644 --- a/test/libevmasm/Optimiser.cpp +++ b/test/libevmasm/Optimiser.cpp @@ -858,6 +858,82 @@ BOOST_AUTO_TEST_CASE(peephole_pop_calldatasize) BOOST_CHECK(items.empty()); } +BOOST_AUTO_TEST_CASE(peephole_commutative_swap1) +{ + vector<Instruction> ops{ + Instruction::ADD, + Instruction::MUL, + Instruction::EQ, + Instruction::AND, + Instruction::OR, + Instruction::XOR + }; + 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() + ); + } +} + +BOOST_AUTO_TEST_CASE(peephole_noncommutative_swap1) +{ + // NOTE: not comprehensive + vector<Instruction> ops{ + Instruction::SUB, + Instruction::DIV, + Instruction::SDIV, + Instruction::MOD, + Instruction::SMOD, + Instruction::EXP, + Instruction::LT, + Instruction::GT + }; + 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() + ); + } +} + BOOST_AUTO_TEST_CASE(jumpdest_removal) { AssemblyItems items{ |