Add constant optimiser for SHR/SHL instructions

This commit is contained in:
Alex Beregszaszi
2018-04-09 20:07:44 +01:00
parent fe61435c27
commit cb352edd26
2 changed files with 11 additions and 0 deletions
+10
View File
@@ -89,6 +89,16 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleList(
u256 mask = (u256(1) << testBit) - 1;
return u256(boost::multiprecision::bit_test(B.d(), testBit) ? B.d() | ~mask : B.d() & mask);
}, false},
{{Instruction::SHL, {A, B}}, [=]{
if (A.d() > 255)
return u256(0);
return u256(bigint(B.d()) << unsigned(A.d()));
}, false},
{{Instruction::SHR, {A, B}}, [=]{
if (A.d() > 255)
return u256(0);
return B.d() >> unsigned(A.d());
}, false},
// invariants involving known constants
{{Instruction::ADD, {X, 0}}, [=]{ return X; }, false},