aboutsummaryrefslogtreecommitdiffstats
path: root/SolidityOptimizer.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-03-23 20:09:25 +0800
committerchriseth <c@ethdev.com>2015-03-27 00:51:26 +0800
commit4e20d0fb6da983ce8716b7710a124e44226a16b0 (patch)
treec91f1f5b7be77d79ea4d33962033d3af0fc49477 /SolidityOptimizer.cpp
parent782e69fbe406de3b4924737b3a3120308a0e096a (diff)
downloaddexon-solidity-4e20d0fb6da983ce8716b7710a124e44226a16b0.tar
dexon-solidity-4e20d0fb6da983ce8716b7710a124e44226a16b0.tar.gz
dexon-solidity-4e20d0fb6da983ce8716b7710a124e44226a16b0.tar.bz2
dexon-solidity-4e20d0fb6da983ce8716b7710a124e44226a16b0.tar.lz
dexon-solidity-4e20d0fb6da983ce8716b7710a124e44226a16b0.tar.xz
dexon-solidity-4e20d0fb6da983ce8716b7710a124e44226a16b0.tar.zst
dexon-solidity-4e20d0fb6da983ce8716b7710a124e44226a16b0.zip
Pattern matching for expression simplification.
Diffstat (limited to 'SolidityOptimizer.cpp')
-rw-r--r--SolidityOptimizer.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/SolidityOptimizer.cpp b/SolidityOptimizer.cpp
index 2ced9743..2d5cff7a 100644
--- a/SolidityOptimizer.cpp
+++ b/SolidityOptimizer.cpp
@@ -240,6 +240,12 @@ BOOST_AUTO_TEST_CASE(cse_unneeded_items)
checkCSE(input, input);
}
+BOOST_AUTO_TEST_CASE(cse_constant_addition)
+{
+ AssemblyItems input{u256(7), u256(8), Instruction::ADD};
+ checkCSE(input, {u256(7 + 8)});
+}
+
BOOST_AUTO_TEST_CASE(cse_invariants)
{
AssemblyItems input{
@@ -262,6 +268,41 @@ BOOST_AUTO_TEST_CASE(cse_subother)
checkCSE({Instruction::SUB}, {Instruction::SUB});
}
+BOOST_AUTO_TEST_CASE(cse_double_negation)
+{
+ checkCSE({Instruction::DUP5, Instruction::NOT, Instruction::NOT}, {Instruction::DUP5});
+}
+
+BOOST_AUTO_TEST_CASE(cse_associativity)
+{
+ AssemblyItems input{
+ Instruction::DUP1,
+ Instruction::DUP1,
+ u256(0),
+ Instruction::OR,
+ Instruction::OR
+ };
+ checkCSE(input, {Instruction::DUP1});
+}
+
+BOOST_AUTO_TEST_CASE(cse_associativity2)
+{
+ AssemblyItems input{
+ u256(0),
+ Instruction::DUP2,
+ u256(2),
+ u256(1),
+ Instruction::DUP6,
+ Instruction::ADD,
+ u256(2),
+ Instruction::ADD,
+ Instruction::ADD,
+ Instruction::ADD,
+ Instruction::ADD
+ };
+ checkCSE(input, {Instruction::DUP2, Instruction::DUP2, Instruction::ADD, u256(5), Instruction::ADD});
+}
+
BOOST_AUTO_TEST_SUITE_END()
}