mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Replace shifts by larger than 255 with 0
This commit is contained in:
parent
65026a0a25
commit
84fbf605aa
@ -5,6 +5,7 @@ Language Features:
|
||||
|
||||
Compiler Features:
|
||||
* SMTChecker: Support arithmetic compound assignment operators.
|
||||
* Optimizer: Add rule for shifts by constants larger than 255 for Constantinople.
|
||||
* Yul: Adds break and continue keywords to for-loop syntax.
|
||||
|
||||
|
||||
|
@ -216,7 +216,7 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleListPart4(
|
||||
|
||||
template <class Pattern>
|
||||
std::vector<SimplificationRule<Pattern>> simplificationRuleListPart5(
|
||||
Pattern,
|
||||
Pattern A,
|
||||
Pattern,
|
||||
Pattern,
|
||||
Pattern X,
|
||||
@ -236,6 +236,22 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleListPart5(
|
||||
});
|
||||
}
|
||||
|
||||
// Replace SHL >=256, X with 0
|
||||
rules.push_back({
|
||||
{Instruction::SHL, {A, X}},
|
||||
[=]() -> Pattern { return u256(0); },
|
||||
true,
|
||||
[=]() { return A.d() >= 256; }
|
||||
});
|
||||
|
||||
// Replace SHR >=256, X with 0
|
||||
rules.push_back({
|
||||
{Instruction::SHR, {A, X}},
|
||||
[=]() -> Pattern { return u256(0); },
|
||||
true,
|
||||
[=]() { return A.d() >= 256; }
|
||||
});
|
||||
|
||||
for (auto const& op: std::vector<Instruction>{
|
||||
Instruction::ADDRESS,
|
||||
Instruction::CALLER,
|
||||
|
@ -1250,6 +1250,48 @@ BOOST_AUTO_TEST_CASE(cse_remove_unwanted_masking_of_address)
|
||||
});
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(cse_replace_too_large_shift)
|
||||
{
|
||||
if (!dev::test::Options::get().evmVersion().hasBitwiseShifting())
|
||||
return;
|
||||
|
||||
checkCSE({
|
||||
Instruction::CALLVALUE,
|
||||
u256(299),
|
||||
Instruction::SHL
|
||||
}, {
|
||||
u256(0)
|
||||
});
|
||||
|
||||
checkCSE({
|
||||
Instruction::CALLVALUE,
|
||||
u256(299),
|
||||
Instruction::SHR
|
||||
}, {
|
||||
u256(0)
|
||||
});
|
||||
|
||||
checkCSE({
|
||||
Instruction::CALLVALUE,
|
||||
u256(255),
|
||||
Instruction::SHL
|
||||
}, {
|
||||
Instruction::CALLVALUE,
|
||||
u256(255),
|
||||
Instruction::SHL
|
||||
});
|
||||
|
||||
checkCSE({
|
||||
Instruction::CALLVALUE,
|
||||
u256(255),
|
||||
Instruction::SHR
|
||||
}, {
|
||||
Instruction::CALLVALUE,
|
||||
u256(255),
|
||||
Instruction::SHR
|
||||
});
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user