Browse Source

Merge pull request #2102 from chriseth/sol_iszeroiszero

Optimize double ISZERO.
cl-refactor
Gav Wood 10 years ago
parent
commit
2669182ea2
  1. 16
      libevmasm/ExpressionClasses.cpp
  2. 10
      test/libsolidity/SolidityOptimizer.cpp

16
libevmasm/ExpressionClasses.cpp

@ -260,6 +260,22 @@ Rules::Rules()
{{Instruction::NOT, {{Instruction::NOT, {X}}}}, [=]{ return X; }},
};
// Double negation of opcodes with binary result
for (auto const& op: vector<Instruction>{
Instruction::EQ,
Instruction::LT,
Instruction::SLT,
Instruction::GT,
Instruction::SGT
})
m_rules.push_back({
{Instruction::ISZERO, {{Instruction::ISZERO, {{op, {X, Y}}}}}},
[=]() -> Pattern { return {op, {X, Y}}; }
});
m_rules.push_back({
{Instruction::ISZERO, {{Instruction::ISZERO, {{Instruction::ISZERO, {X}}}}}},
[=]() -> Pattern { return {Instruction::ISZERO, {X}}; }
});
// Associative operations
for (auto const& opFun: vector<pair<Instruction,function<u256(u256 const&,u256 const&)>>>{
{Instruction::ADD, plus<u256>()},

10
test/libsolidity/SolidityOptimizer.cpp

@ -440,6 +440,16 @@ BOOST_AUTO_TEST_CASE(cse_double_negation)
checkCSE({Instruction::DUP5, Instruction::NOT, Instruction::NOT}, {Instruction::DUP5});
}
BOOST_AUTO_TEST_CASE(cse_double_iszero)
{
checkCSE({Instruction::GT, Instruction::ISZERO, Instruction::ISZERO}, {Instruction::GT});
checkCSE({Instruction::GT, Instruction::ISZERO}, {Instruction::GT, Instruction::ISZERO});
checkCSE(
{Instruction::ISZERO, Instruction::ISZERO, Instruction::ISZERO},
{Instruction::ISZERO}
);
}
BOOST_AUTO_TEST_CASE(cse_associativity)
{
AssemblyItems input{

Loading…
Cancel
Save