From d3abbd5610824ad82337d9926655da02d45063ea Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 8 Jul 2020 20:13:11 +0200 Subject: [PATCH] Remove unneccessary masking of tags. --- Changelog.md | 1 + libevmasm/PeepholeOptimiser.cpp | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 9795ecb51..ca81e04d8 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,7 @@ Compiler Features: * Code Generator: Evaluate ``keccak256`` of string literals at compile-time. + * Peephole Optimizer: Remove unnecessary masking of tags. Bugfixes: * Type Checker: Fix overload resolution in combination with ``{value: ...}``. diff --git a/libevmasm/PeepholeOptimiser.cpp b/libevmasm/PeepholeOptimiser.cpp index 861cae0f2..dd5f9399c 100644 --- a/libevmasm/PeepholeOptimiser.cpp +++ b/libevmasm/PeepholeOptimiser.cpp @@ -266,9 +266,10 @@ struct TagConjunctions: SimplePeepholeOptimizerMethod std::back_insert_iterator _out ) { + if (_and != Instruction::AND) + return false; if ( _pushTag.type() == PushTag && - _and == Instruction::AND && _pushConstant.type() == Push && (_pushConstant.data() & u256(0xFFFFFFFF)) == u256(0xFFFFFFFF) ) @@ -276,6 +277,16 @@ struct TagConjunctions: SimplePeepholeOptimizerMethod *_out = _pushTag; return true; } + else if ( + // tag and constant are swapped + _pushConstant.type() == PushTag && + _pushTag.type() == Push && + (_pushTag.data() & u256(0xFFFFFFFF)) == u256(0xFFFFFFFF) + ) + { + *_out = _pushConstant; + return true; + } else return false; }