From 172e208c6aa70956389ce7efb90b64ac32140588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Thu, 14 Jun 2018 14:29:42 -0300 Subject: Add TruthyAnd Peephole optimization --- test/libevmasm/Optimiser.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test') diff --git a/test/libevmasm/Optimiser.cpp b/test/libevmasm/Optimiser.cpp index 4b399a14..8e4946c3 100644 --- a/test/libevmasm/Optimiser.cpp +++ b/test/libevmasm/Optimiser.cpp @@ -967,6 +967,18 @@ BOOST_AUTO_TEST_CASE(peephole_swap_comparison) } } +BOOST_AUTO_TEST_CASE(peephole_truthy_and) +{ + AssemblyItems items{ + u256(0), + Instruction::NOT, + Instruction::AND + }; + PeepholeOptimiser peepOpt(items); + BOOST_REQUIRE(peepOpt.optimise()); + BOOST_CHECK(items.empty()); +} + BOOST_AUTO_TEST_CASE(jumpdest_removal) { AssemblyItems items{ -- cgit v1.2.3 From 804eb3ef9d45cd9e4f57ba9b4bd60fea36135ca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Mon, 18 Jun 2018 10:49:06 -0300 Subject: Improves peephole_truthy_and test case --- test/libevmasm/Optimiser.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/libevmasm/Optimiser.cpp b/test/libevmasm/Optimiser.cpp index 8e4946c3..5687ffcc 100644 --- a/test/libevmasm/Optimiser.cpp +++ b/test/libevmasm/Optimiser.cpp @@ -970,13 +970,26 @@ BOOST_AUTO_TEST_CASE(peephole_swap_comparison) BOOST_AUTO_TEST_CASE(peephole_truthy_and) { AssemblyItems items{ + AssemblyItem(Tag, 1), + Instruction::BALANCE, u256(0), Instruction::NOT, - Instruction::AND + Instruction::AND, + AssemblyItem(PushTag, 1), + Instruction::JUMPI + }; + AssemblyItems expectation{ + AssemblyItem(Tag, 1), + Instruction::BALANCE, + AssemblyItem(PushTag, 1), + Instruction::JUMPI }; PeepholeOptimiser peepOpt(items); BOOST_REQUIRE(peepOpt.optimise()); - BOOST_CHECK(items.empty()); + BOOST_CHECK_EQUAL_COLLECTIONS( + items.begin(), items.end(), + expectation.begin(), expectation.end() + ); } BOOST_AUTO_TEST_CASE(jumpdest_removal) -- cgit v1.2.3