aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2018-01-04 20:05:01 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-02-13 06:47:04 +0800
commit037b97ef4a53c30f2800777a88d754a898bccc2b (patch)
tree18e053b78cf0e6f02baabc1f549568fd54567ea6
parent954903b50540456906fd7ba909d7d663e2bd7a7f (diff)
downloaddexon-solidity-037b97ef4a53c30f2800777a88d754a898bccc2b.tar
dexon-solidity-037b97ef4a53c30f2800777a88d754a898bccc2b.tar.gz
dexon-solidity-037b97ef4a53c30f2800777a88d754a898bccc2b.tar.bz2
dexon-solidity-037b97ef4a53c30f2800777a88d754a898bccc2b.tar.lz
dexon-solidity-037b97ef4a53c30f2800777a88d754a898bccc2b.tar.xz
dexon-solidity-037b97ef4a53c30f2800777a88d754a898bccc2b.tar.zst
dexon-solidity-037b97ef4a53c30f2800777a88d754a898bccc2b.zip
Replace MOD with AND if constant is power of 2
-rw-r--r--libevmasm/RuleList.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/libevmasm/RuleList.h b/libevmasm/RuleList.h
index 2312d673..da522cec 100644
--- a/libevmasm/RuleList.h
+++ b/libevmasm/RuleList.h
@@ -153,6 +153,17 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleList(
{{Instruction::OR, {{Instruction::NOT, {X}}, X}}, [=]{ return ~u256(0); }, true},
};
+ // Replace MOD X, <power-of-two> with AND X, <power-of-two> - 1
+ for (size_t i = 0; i < 256; ++i)
+ {
+ u256 value = u256(1) << i;
+ rules.push_back({
+ {Instruction::MOD, {X, value}},
+ [=]() -> Pattern { return {Instruction::AND, {X, value - 1}}; },
+ false
+ });
+ }
+
// Double negation of opcodes with boolean result
for (auto const& op: std::vector<Instruction>{
Instruction::EQ,