mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Replace comparison operators with opposites if preceded by SWAP1
This commit is contained in:
@@ -888,7 +888,7 @@ BOOST_AUTO_TEST_CASE(peephole_commutative_swap1)
|
||||
PeepholeOptimiser peepOpt(items);
|
||||
BOOST_REQUIRE(peepOpt.optimise());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
items.begin(), items.end(),
|
||||
items.begin(), items.end(),
|
||||
expectation.begin(), expectation.end()
|
||||
);
|
||||
}
|
||||
@@ -903,9 +903,7 @@ BOOST_AUTO_TEST_CASE(peephole_noncommutative_swap1)
|
||||
Instruction::SDIV,
|
||||
Instruction::MOD,
|
||||
Instruction::SMOD,
|
||||
Instruction::EXP,
|
||||
Instruction::LT,
|
||||
Instruction::GT
|
||||
Instruction::EXP
|
||||
};
|
||||
for (Instruction const op: ops)
|
||||
{
|
||||
@@ -928,7 +926,42 @@ BOOST_AUTO_TEST_CASE(peephole_noncommutative_swap1)
|
||||
PeepholeOptimiser peepOpt(items);
|
||||
BOOST_REQUIRE(!peepOpt.optimise());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
items.begin(), items.end(),
|
||||
items.begin(), items.end(),
|
||||
expectation.begin(), expectation.end()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(peephole_swap_comparison)
|
||||
{
|
||||
map<Instruction, Instruction> swappableOps{
|
||||
{ Instruction::LT, Instruction::GT },
|
||||
{ Instruction::GT, Instruction::LT },
|
||||
{ Instruction::SLT, Instruction::SGT },
|
||||
{ Instruction::SGT, Instruction::SLT }
|
||||
};
|
||||
|
||||
for (auto const& op: swappableOps)
|
||||
{
|
||||
AssemblyItems items{
|
||||
u256(1),
|
||||
u256(2),
|
||||
Instruction::SWAP1,
|
||||
op.first,
|
||||
u256(4),
|
||||
u256(5)
|
||||
};
|
||||
AssemblyItems expectation{
|
||||
u256(1),
|
||||
u256(2),
|
||||
op.second,
|
||||
u256(4),
|
||||
u256(5)
|
||||
};
|
||||
PeepholeOptimiser peepOpt(items);
|
||||
BOOST_REQUIRE(peepOpt.optimise());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
items.begin(), items.end(),
|
||||
expectation.begin(), expectation.end()
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user