aboutsummaryrefslogtreecommitdiffstats
path: root/libevmasm
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-05-10 17:46:44 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-04-10 03:07:44 +0800
commitcb352edd26f55adda63dde6cb66931089aff6656 (patch)
tree391bdc017eea84dce51a29165cc93493f0cb0fc2 /libevmasm
parentfe61435c273bf43ac1a20d8bc97b6935a54b7117 (diff)
downloaddexon-solidity-cb352edd26f55adda63dde6cb66931089aff6656.tar.gz
dexon-solidity-cb352edd26f55adda63dde6cb66931089aff6656.tar.zst
dexon-solidity-cb352edd26f55adda63dde6cb66931089aff6656.zip
Add constant optimiser for SHR/SHL instructions
Diffstat (limited to 'libevmasm')
-rw-r--r--libevmasm/RuleList.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/libevmasm/RuleList.h b/libevmasm/RuleList.h
index da522cec..abcf170c 100644
--- a/libevmasm/RuleList.h
+++ b/libevmasm/RuleList.h
@@ -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},