From c0afb4549ebecfc5e4ad05e8e24d26d92f4ec64d Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 1 Aug 2016 23:13:56 +0200 Subject: [PATCH] Further fixes to the optimizer. --- libevmasm/ControlFlowGraph.cpp | 7 ++++--- libevmasm/ControlFlowGraph.h | 2 +- test/libsolidity/SolidityOptimizer.cpp | 5 ++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/libevmasm/ControlFlowGraph.cpp b/libevmasm/ControlFlowGraph.cpp index 61b24e4b6..d48015625 100644 --- a/libevmasm/ControlFlowGraph.cpp +++ b/libevmasm/ControlFlowGraph.cpp @@ -250,10 +250,11 @@ void ControlFlowGraph::gatherKnowledge() KnownStatePointer state = item.state; if (block.startState) { - if (m_joinKnowledge) - state->reduceToCommonKnowledge(*block.startState, !item.blocksSeen.count(item.blockId)); - else + // We call reduceToCommonKnowledge even in the non-join setting to get the correct + // sequence number + if (!m_joinKnowledge) state->reset(); + state->reduceToCommonKnowledge(*block.startState, !item.blocksSeen.count(item.blockId)); if (*state == *block.startState) continue; } diff --git a/libevmasm/ControlFlowGraph.h b/libevmasm/ControlFlowGraph.h index a6a9df8e0..03a1f717c 100644 --- a/libevmasm/ControlFlowGraph.h +++ b/libevmasm/ControlFlowGraph.h @@ -116,7 +116,7 @@ private: unsigned m_lastUsedId = 0; AssemblyItems const& m_items; - bool m_joinKnowledge; + bool m_joinKnowledge = true; std::map m_blocks; }; diff --git a/test/libsolidity/SolidityOptimizer.cpp b/test/libsolidity/SolidityOptimizer.cpp index 2e4ed4b39..206f23fb5 100644 --- a/test/libsolidity/SolidityOptimizer.cpp +++ b/test/libsolidity/SolidityOptimizer.cpp @@ -282,6 +282,8 @@ BOOST_AUTO_TEST_CASE(storage_write_in_loops) compareVersions("f(uint256)", 36); } +// Test disabled with https://github.com/ethereum/solidity/pull/762 +// Information in joining branches is not retained anymore. BOOST_AUTO_TEST_CASE(retain_information_in_branches) { // This tests that the optimizer knows that we already have "z == sha3(y)" inside both branches. @@ -315,7 +317,8 @@ BOOST_AUTO_TEST_CASE(retain_information_in_branches) if (_instr == Instruction::SHA3) numSHA3s++; }); - BOOST_CHECK_EQUAL(1, numSHA3s); +// TEST DISABLED - OPTIMIZER IS NOT EFFECTIVE ON THIS ONE ANYMORE +// BOOST_CHECK_EQUAL(1, numSHA3s); } BOOST_AUTO_TEST_CASE(store_tags_as_unions)