From 037b97ef4a53c30f2800777a88d754a898bccc2b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 4 Jan 2018 12:05:01 +0000 Subject: Replace MOD with AND if constant is power of 2 --- libevmasm/RuleList.h | 11 +++++++++++ 1 file changed, 11 insertions(+) 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> simplificationRuleList( {{Instruction::OR, {{Instruction::NOT, {X}}, X}}, [=]{ return ~u256(0); }, true}, }; + // Replace MOD X, with AND X, - 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::EQ, -- cgit v1.2.3