From 571f400a3e31c0b84d5b41078e3f62de22f4e4e8 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 13 Mar 2019 12:00:15 +0100 Subject: [PATCH] Complete the GT/LT rules. --- Changelog.md | 1 + libevmasm/RuleList.h | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index b1e45ca1b..855b6ec72 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,6 +9,7 @@ Language Features: Compiler Features: + * Optimizer: Add rules for ``lt``-comparisons with constants. * Peephole Optimizer: Remove double ``iszero`` before ``jumpi``. * SMTChecker: Support enums without typecast. * SMTChecker: Support one-dimensional arrays. diff --git a/libevmasm/RuleList.h b/libevmasm/RuleList.h index 046633d17..74d88e46f 100644 --- a/libevmasm/RuleList.h +++ b/libevmasm/RuleList.h @@ -146,10 +146,12 @@ std::vector> simplificationRuleListPart2( {{Instruction::SHR, {0, X}}, [=]{ return X; }, false}, {{Instruction::SHL, {X, 0}}, [=]{ return u256(0); }, true}, {{Instruction::SHR, {X, 0}}, [=]{ return u256(0); }, true}, - {{Instruction::LT, {X, 0}}, [=]{ return u256(0); }, true}, {{Instruction::GT, {X, 0}}, [=]() -> Pattern { return {Instruction::ISZERO, {{Instruction::ISZERO, {X}}}}; }, false}, + {{Instruction::LT, {0, X}}, [=]() -> Pattern { return {Instruction::ISZERO, {{Instruction::ISZERO, {X}}}}; }, false}, {{Instruction::GT, {X, ~u256(0)}}, [=]{ return u256(0); }, true}, + {{Instruction::LT, {~u256(0), X}}, [=]{ return u256(0); }, true}, {{Instruction::GT, {0, X}}, [=]{ return u256(0); }, true}, + {{Instruction::LT, {X, 0}}, [=]{ return u256(0); }, true}, {{Instruction::AND, {{Instruction::BYTE, {X, Y}}, {u256(0xff)}}}, [=]() -> Pattern { return {Instruction::BYTE, {X, Y}}; }, false}, {{Instruction::BYTE, {X, 31}}, [=]() -> Pattern { return {Instruction::AND, {X, u256(0xff)}}; }, false} };