mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Test multiple instructions with the (non)commutative peephole optimiser
This commit is contained in:
parent
17bcabb6cf
commit
be6051bead
@ -860,53 +860,78 @@ BOOST_AUTO_TEST_CASE(peephole_pop_calldatasize)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(peephole_commutative_swap1)
|
BOOST_AUTO_TEST_CASE(peephole_commutative_swap1)
|
||||||
{
|
{
|
||||||
AssemblyItems items{
|
vector<Instruction> ops{
|
||||||
u256(1),
|
|
||||||
u256(2),
|
|
||||||
Instruction::SWAP1,
|
|
||||||
Instruction::ADD,
|
Instruction::ADD,
|
||||||
u256(4),
|
Instruction::MUL,
|
||||||
u256(5)
|
Instruction::EQ,
|
||||||
|
Instruction::AND,
|
||||||
|
Instruction::OR,
|
||||||
|
Instruction::XOR
|
||||||
};
|
};
|
||||||
AssemblyItems expectation{
|
for (Instruction const op: ops)
|
||||||
u256(1),
|
{
|
||||||
u256(2),
|
AssemblyItems items{
|
||||||
Instruction::ADD,
|
u256(1),
|
||||||
u256(4),
|
u256(2),
|
||||||
u256(5)
|
Instruction::SWAP1,
|
||||||
};
|
op,
|
||||||
PeepholeOptimiser peepOpt(items);
|
u256(4),
|
||||||
BOOST_REQUIRE(peepOpt.optimise());
|
u256(5)
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
};
|
||||||
|
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(),
|
items.begin(), items.end(),
|
||||||
expectation.begin(), expectation.end()
|
expectation.begin(), expectation.end()
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(peephole_noncommutative_swap1)
|
BOOST_AUTO_TEST_CASE(peephole_noncommutative_swap1)
|
||||||
{
|
{
|
||||||
AssemblyItems items{
|
// NOTE: not comprehensive
|
||||||
u256(1),
|
vector<Instruction> ops{
|
||||||
u256(2),
|
|
||||||
Instruction::SWAP1,
|
|
||||||
Instruction::SUB,
|
Instruction::SUB,
|
||||||
u256(4),
|
Instruction::DIV,
|
||||||
u256(5)
|
Instruction::SDIV,
|
||||||
|
Instruction::MOD,
|
||||||
|
Instruction::SMOD,
|
||||||
|
Instruction::EXP,
|
||||||
|
Instruction::LT,
|
||||||
|
Instruction::GT
|
||||||
};
|
};
|
||||||
AssemblyItems expectation{
|
for (Instruction const op: ops)
|
||||||
u256(1),
|
{
|
||||||
u256(2),
|
AssemblyItems items{
|
||||||
Instruction::SWAP1,
|
u256(1),
|
||||||
Instruction::SUB,
|
u256(2),
|
||||||
u256(4),
|
Instruction::SWAP1,
|
||||||
u256(5)
|
op,
|
||||||
};
|
u256(4),
|
||||||
PeepholeOptimiser peepOpt(items);
|
u256(5)
|
||||||
BOOST_REQUIRE(!peepOpt.optimise());
|
};
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
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(),
|
items.begin(), items.end(),
|
||||||
expectation.begin(), expectation.end()
|
expectation.begin(), expectation.end()
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(jumpdest_removal)
|
BOOST_AUTO_TEST_CASE(jumpdest_removal)
|
||||||
|
Loading…
Reference in New Issue
Block a user