mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Optimize obsolete ANDs in combination with certain SHIFTs
This commit is contained in:
@@ -1180,6 +1180,84 @@ BOOST_AUTO_TEST_CASE(cse_sub_zero)
|
||||
});
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(cse_remove_redundant_shift_masking)
|
||||
{
|
||||
if (!dev::test::Options::get().evmVersion().hasBitwiseShifting())
|
||||
return;
|
||||
|
||||
for (int i = 1; i < 256; i++)
|
||||
{
|
||||
checkCSE({
|
||||
u256(boost::multiprecision::pow(u256(2), i)-1),
|
||||
Instruction::CALLVALUE,
|
||||
u256(256-i),
|
||||
Instruction::SHR,
|
||||
Instruction::AND
|
||||
}, {
|
||||
Instruction::CALLVALUE,
|
||||
u256(256-i),
|
||||
Instruction::SHR,
|
||||
});
|
||||
|
||||
checkCSE({
|
||||
Instruction::CALLVALUE,
|
||||
u256(256-i),
|
||||
Instruction::SHR,
|
||||
u256(boost::multiprecision::pow(u256(2), i)-1),
|
||||
Instruction::AND
|
||||
}, {
|
||||
Instruction::CALLVALUE,
|
||||
u256(256-i),
|
||||
Instruction::SHR,
|
||||
});
|
||||
}
|
||||
|
||||
// Check that opt. does NOT trigger
|
||||
for (int i = 1; i < 255; i++)
|
||||
{
|
||||
checkCSE({
|
||||
u256(boost::multiprecision::pow(u256(2), i)-1),
|
||||
Instruction::CALLVALUE,
|
||||
u256(255-i),
|
||||
Instruction::SHR,
|
||||
Instruction::AND
|
||||
}, { // Opt. did some reordering
|
||||
Instruction::CALLVALUE,
|
||||
u256(255-i),
|
||||
Instruction::SHR,
|
||||
u256(boost::multiprecision::pow(u256(2), i)-1),
|
||||
Instruction::AND
|
||||
});
|
||||
|
||||
checkCSE({
|
||||
Instruction::CALLVALUE,
|
||||
u256(255-i),
|
||||
Instruction::SHR,
|
||||
u256(boost::multiprecision::pow(u256(2), i)-1),
|
||||
Instruction::AND
|
||||
}, { // Opt. did some reordering
|
||||
u256(boost::multiprecision::pow(u256(2), i)-1),
|
||||
Instruction::CALLVALUE,
|
||||
u256(255-i),
|
||||
Instruction::SHR,
|
||||
Instruction::AND
|
||||
});
|
||||
}
|
||||
|
||||
//(x >> (31*8)) & 0xffffffff
|
||||
checkCSE({
|
||||
Instruction::CALLVALUE,
|
||||
u256(31*8),
|
||||
Instruction::SHR,
|
||||
u256(0xffffffff),
|
||||
Instruction::AND
|
||||
}, {
|
||||
Instruction::CALLVALUE,
|
||||
u256(31*8),
|
||||
Instruction::SHR
|
||||
});
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(cse_remove_unwanted_masking_of_address)
|
||||
{
|
||||
vector<Instruction> ops{
|
||||
|
||||
Reference in New Issue
Block a user