diff --git a/.circleci/config.yml b/.circleci/config.yml index 65e7113a3..65adf9ee3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -504,28 +504,14 @@ defaults: binary_type: solcjs compile_only: 1 nodejs_version: '14' - - job_native_compile_ext_gnosis: &job_native_compile_ext_gnosis - <<: *workflow_ubuntu2004_static - name: t_native_compile_ext_gnosis - project: gnosis - binary_type: native - compile_only: 1 - nodejs_version: '14' - job_native_test_ext_gnosis: &job_native_test_ext_gnosis - <<: *workflow_emscripten + <<: *workflow_ubuntu2004_static name: t_native_test_ext_gnosis project: gnosis binary_type: native - # NOTE: Tests do not start on node.js 14 ("ganache-cli exited early with code 1"). - nodejs_version: '12' - - job_native_test_ext_gnosis_v2: &job_native_test_ext_gnosis_v2 - <<: *workflow_ubuntu2004_static - name: t_native_test_ext_gnosis_v2 - project: gnosis-v2 - binary_type: native - # NOTE: Tests do not start on node.js 14 ("ganache-cli exited early with code 1"). - nodejs_version: '12' + # NOTE: Tests crash on nodejs 17: "Error: error:0308010C:digital envelope routines::unsupported" + nodejs_version: '16' - job_native_test_ext_zeppelin: &job_native_test_ext_zeppelin <<: *workflow_ubuntu2004_static name: t_native_test_ext_zeppelin @@ -1466,12 +1452,8 @@ workflows: - t_ems_ext_hardhat: *workflow_emscripten - t_ems_ext: *job_ems_compile_ext_colony - - t_ems_ext: *job_native_compile_ext_gnosis - # FIXME: Gnosis tests are pretty flaky right now. They often fail on CircleCI due to random ProviderError - # and there are also other less frequent problems. See https://github.com/gnosis/safe-contracts/issues/216. - #-t_ems_ext: *job_native_test_ext_gnosis - - t_ems_ext: *job_native_test_ext_gnosis_v2 + - t_ems_ext: *job_native_test_ext_gnosis - t_ems_ext: *job_native_test_ext_zeppelin - t_ems_ext: *job_native_test_ext_ens - t_ems_ext: *job_native_test_ext_trident @@ -1488,8 +1470,7 @@ workflows: <<: *workflow_trigger_on_tags requires: - t_ems_compile_ext_colony - - t_native_compile_ext_gnosis - - t_native_test_ext_gnosis_v2 + - t_native_test_ext_gnosis - t_native_test_ext_zeppelin - t_native_test_ext_ens - t_native_test_ext_trident diff --git a/Changelog.md b/Changelog.md index 63588731f..8b9fa530c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,6 +6,8 @@ Language Features: Compiler Features: * JSON-AST: Added selector field for errors and events. + * Peephole Optimizer: Optimize comparisons in front of conditional jumps and conditional jumps across a single unconditional jump. + * Yul Optimizer: Remove ``sstore`` and ``mstore`` operations that are never read from. Bugfixes: * Yul IR Code Generation: Optimize embedded creation code with correct settings. This fixes potential mismatches between the constructor code of a contract compiled in isolation and the bytecode in ``type(C).creationCode``, resp. the bytecode used for ``new C(...)``. diff --git a/docs/contracts/interfaces.rst b/docs/contracts/interfaces.rst index a4581a15f..cc71cf64e 100644 --- a/docs/contracts/interfaces.rst +++ b/docs/contracts/interfaces.rst @@ -10,7 +10,7 @@ Interfaces are similar to abstract contracts, but they cannot have any functions There are further restrictions: - They cannot inherit from other contracts, but they can inherit from other interfaces. -- All declared functions must be external. +- All declared functions must be external in the interface, even if they are public in the contract. - They cannot declare a constructor. - They cannot declare state variables. - They cannot declare modifiers. diff --git a/libevmasm/PeepholeOptimiser.cpp b/libevmasm/PeepholeOptimiser.cpp index b04c2158c..31fb11f6f 100644 --- a/libevmasm/PeepholeOptimiser.cpp +++ b/libevmasm/PeepholeOptimiser.cpp @@ -233,6 +233,65 @@ struct IsZeroIsZeroJumpI: SimplePeepholeOptimizerMethod } }; +struct EqIsZeroJumpI: SimplePeepholeOptimizerMethod +{ + static size_t applySimple( + AssemblyItem const& _eq, + AssemblyItem const& _iszero, + AssemblyItem const& _pushTag, + AssemblyItem const& _jumpi, + std::back_insert_iterator _out + ) + { + if ( + _eq == Instruction::EQ && + _iszero == Instruction::ISZERO && + _pushTag.type() == PushTag && + _jumpi == Instruction::JUMPI + ) + { + *_out = AssemblyItem(Instruction::SUB, _eq.location()); + *_out = _pushTag; + *_out = _jumpi; + return true; + } + else + return false; + } +}; + +// push_tag_1 jumpi push_tag_2 jump tag_1: -> iszero push_tag_2 jumpi tag_1: +struct DoubleJump: SimplePeepholeOptimizerMethod +{ + static size_t applySimple( + AssemblyItem const& _pushTag1, + AssemblyItem const& _jumpi, + AssemblyItem const& _pushTag2, + AssemblyItem const& _jump, + AssemblyItem const& _tag1, + std::back_insert_iterator _out + ) + { + if ( + _pushTag1.type() == PushTag && + _jumpi == Instruction::JUMPI && + _pushTag2.type() == PushTag && + _jump == Instruction::JUMP && + _tag1.type() == Tag && + _pushTag1.data() == _tag1.data() + ) + { + *_out = AssemblyItem(Instruction::ISZERO, _jumpi.location()); + *_out = _pushTag2; + *_out = _jumpi; + *_out = _tag1; + return true; + } + else + return false; + } +}; + struct JumpToNext: SimplePeepholeOptimizerMethod { static size_t applySimple( @@ -372,7 +431,7 @@ bool PeepholeOptimiser::optimise() applyMethods( state, PushPop(), OpPop(), DoublePush(), DoubleSwap(), CommutativeSwap(), SwapComparison(), - DupSwap(), IsZeroIsZeroJumpI(), JumpToNext(), UnreachableCode(), + DupSwap(), IsZeroIsZeroJumpI(), EqIsZeroJumpI(), DoubleJump(), JumpToNext(), UnreachableCode(), TagConjunctions(), TruthyAnd(), Identity() ); if (m_optimisedItems.size() < m_items.size() || ( diff --git a/libevmasm/SemanticInformation.cpp b/libevmasm/SemanticInformation.cpp index 8a1266bcf..acbcaa5c0 100644 --- a/libevmasm/SemanticInformation.cpp +++ b/libevmasm/SemanticInformation.cpp @@ -121,7 +121,9 @@ vector SemanticInformation::readWriteOperations( Location::Memory, Effect::Write, paramCount - 2, - paramCount - 1, + // Length is in paramCount - 1, but it is only a max length, + // there is no guarantee that the full area is written to. + {}, {} }); return operations; diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index c84d79785..77e9af866 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -2341,6 +2341,11 @@ TypeResult StructType::interfaceType(bool _inLibrary) const return *m_interfaceType_library; } +Declaration const* StructType::typeDefinition() const +{ + return &structDefinition(); +} + BoolResult StructType::validForLocation(DataLocation _loc) const { for (auto const& member: m_struct.members()) @@ -2473,6 +2478,11 @@ Type const* EnumType::encodingType() const return TypeProvider::uint(8); } +Declaration const* EnumType::typeDefinition() const +{ + return &enumDefinition(); +} + TypeResult EnumType::unaryOperatorResult(Token _operator) const { return _operator == Token::Delete ? TypeProvider::emptyTuple() : nullptr; @@ -2541,6 +2551,11 @@ Type const& UserDefinedValueType::underlyingType() const return *type; } +Declaration const* UserDefinedValueType::typeDefinition() const +{ + return &m_definition; +} + string UserDefinedValueType::richIdentifier() const { return "t_userDefinedValueType" + parenthesizeIdentifier(m_definition.name()) + to_string(m_definition.id()); diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 9b030f65a..9b3080769 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -369,6 +369,10 @@ public: /// are returned without modification. virtual TypeResult interfaceType(bool /*_inLibrary*/) const { return nullptr; } + /// @returns the declaration of a user defined type (enum, struct, user defined value type). + /// Returns nullptr otherwise. + virtual Declaration const* typeDefinition() const { return nullptr; } + /// Clears all internally cached values (if any). virtual void clearCache() const; @@ -1004,6 +1008,8 @@ public: Type const* encodingType() const override; TypeResult interfaceType(bool _inLibrary) const override; + Declaration const* typeDefinition() const override; + BoolResult validForLocation(DataLocation _loc) const override; bool recursive() const; @@ -1069,6 +1075,8 @@ public: return _inLibrary ? this : encodingType(); } + Declaration const* typeDefinition() const override; + EnumDefinition const& enumDefinition() const { return m_enum; } /// @returns the value that the string has in the Enum unsigned int memberValue(ASTString const& _member) const; @@ -1101,6 +1109,9 @@ public: TypeResult binaryOperatorResult(Token, Type const*) const override { return nullptr; } Type const* encodingType() const override { return &underlyingType(); } TypeResult interfaceType(bool /* _inLibrary */) const override {return &underlyingType(); } + + Declaration const* typeDefinition() const override; + std::string richIdentifier() const override; bool operator==(Type const& _other) const override; diff --git a/libsolidity/interface/OptimiserSettings.h b/libsolidity/interface/OptimiserSettings.h index e1c35e9ea..e233048c1 100644 --- a/libsolidity/interface/OptimiserSettings.h +++ b/libsolidity/interface/OptimiserSettings.h @@ -55,7 +55,7 @@ struct OptimiserSettings "xa[rul]" // Prune a bit more in SSA "xa[r]cL" // Turn into SSA again and simplify "gvif" // Run full inliner - "CTUca[r]LsTFOtfDnca[r]Iulc" // SSA plus simplify + "CTUca[r]LSsTFOtfDnca[r]Iulc" // SSA plus simplify "]" "jmul[jul] VcTOcul jmul"; // Make source short and pretty diff --git a/libyul/CMakeLists.txt b/libyul/CMakeLists.txt index fde673e3d..806f094fe 100644 --- a/libyul/CMakeLists.txt +++ b/libyul/CMakeLists.txt @@ -179,6 +179,8 @@ add_library(yul optimiser/UnusedAssignEliminator.h optimiser/UnusedStoreBase.cpp optimiser/UnusedStoreBase.h + optimiser/UnusedStoreEliminator.cpp + optimiser/UnusedStoreEliminator.h optimiser/Rematerialiser.cpp optimiser/Rematerialiser.h optimiser/SMTSolver.cpp diff --git a/libyul/optimiser/StructuralSimplifier.cpp b/libyul/optimiser/StructuralSimplifier.cpp index 5b1ae2550..ca8f94239 100644 --- a/libyul/optimiser/StructuralSimplifier.cpp +++ b/libyul/optimiser/StructuralSimplifier.cpp @@ -55,6 +55,30 @@ OptionalStatements replaceConstArgSwitch(Switch& _switchStmt, u256 const& _const return optional>{vector{}}; } +optional hasLiteralValue(Expression const& _expression) +{ + if (holds_alternative(_expression)) + return valueOfLiteral(std::get(_expression)); + else + return std::optional(); +} + +bool expressionAlwaysTrue(Expression const& _expression) +{ + if (std::optional value = hasLiteralValue(_expression)) + return *value != 0; + else + return false; +} + +bool expressionAlwaysFalse(Expression const& _expression) +{ + if (std::optional value = hasLiteralValue(_expression)) + return *value == 0; + else + return false; +} + } void StructuralSimplifier::run(OptimiserStepContext&, Block& _ast) @@ -103,27 +127,3 @@ void StructuralSimplifier::simplify(std::vector& _statements) } ); } - -bool StructuralSimplifier::expressionAlwaysTrue(Expression const& _expression) -{ - if (std::optional value = hasLiteralValue(_expression)) - return *value != 0; - else - return false; -} - -bool StructuralSimplifier::expressionAlwaysFalse(Expression const& _expression) -{ - if (std::optional value = hasLiteralValue(_expression)) - return *value == 0; - else - return false; -} - -std::optional StructuralSimplifier::hasLiteralValue(Expression const& _expression) const -{ - if (holds_alternative(_expression)) - return valueOfLiteral(std::get(_expression)); - else - return std::optional(); -} diff --git a/libyul/optimiser/StructuralSimplifier.h b/libyul/optimiser/StructuralSimplifier.h index 3fd59efde..734b2e53a 100644 --- a/libyul/optimiser/StructuralSimplifier.h +++ b/libyul/optimiser/StructuralSimplifier.h @@ -18,7 +18,6 @@ #pragma once #include -#include #include #include @@ -50,9 +49,6 @@ private: StructuralSimplifier() = default; void simplify(std::vector& _statements); - bool expressionAlwaysTrue(Expression const& _expression); - bool expressionAlwaysFalse(Expression const& _expression); - std::optional hasLiteralValue(Expression const& _expression) const; }; } diff --git a/libyul/optimiser/Suite.cpp b/libyul/optimiser/Suite.cpp index 0f2194061..181c9bdcb 100644 --- a/libyul/optimiser/Suite.cpp +++ b/libyul/optimiser/Suite.cpp @@ -57,6 +57,7 @@ #include #include #include +#include #include #include #include @@ -222,6 +223,7 @@ map> const& OptimiserSuite::allSteps() LoadResolver, LoopInvariantCodeMotion, UnusedAssignEliminator, + UnusedStoreEliminator, ReasoningBasedSimplifier, Rematerialiser, SSAReverser, @@ -264,6 +266,7 @@ map const& OptimiserSuite::stepNameToAbbreviationMap() {LoopInvariantCodeMotion::name, 'M'}, {ReasoningBasedSimplifier::name, 'R'}, {UnusedAssignEliminator::name, 'r'}, + {UnusedStoreEliminator::name, 'S'}, {Rematerialiser::name, 'm'}, {SSAReverser::name, 'V'}, {SSATransform::name, 'a'}, diff --git a/libyul/optimiser/UnusedStoreEliminator.cpp b/libyul/optimiser/UnusedStoreEliminator.cpp new file mode 100644 index 000000000..e3ff2d77a --- /dev/null +++ b/libyul/optimiser/UnusedStoreEliminator.cpp @@ -0,0 +1,379 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see . +*/ +// SPDX-License-Identifier: GPL-3.0 +/** + * Optimiser component that removes stores to memory and storage slots that are not used + * or overwritten later on. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include + +using namespace std; +using namespace solidity; +using namespace solidity::yul; + +/// Variable names for special constants that can never appear in actual Yul code. +static string const zero{"@ 0"}; +static string const one{"@ 1"}; +static string const thirtyTwo{"@ 32"}; + + +void UnusedStoreEliminator::run(OptimiserStepContext& _context, Block& _ast) +{ + map functionSideEffects = SideEffectsPropagator::sideEffects( + _context.dialect, + CallGraphGenerator::callGraph(_ast) + ); + + SSAValueTracker ssaValues; + ssaValues(_ast); + map values; + for (auto const& [name, expression]: ssaValues.values()) + values[name] = AssignedValue{expression, {}}; + Expression const zeroLiteral{Literal{{}, LiteralKind::Number, YulString{"0"}, {}}}; + Expression const oneLiteral{Literal{{}, LiteralKind::Number, YulString{"1"}, {}}}; + Expression const thirtyTwoLiteral{Literal{{}, LiteralKind::Number, YulString{"32"}, {}}}; + values[YulString{zero}] = AssignedValue{&zeroLiteral, {}}; + values[YulString{one}] = AssignedValue{&oneLiteral, {}}; + values[YulString{thirtyTwo}] = AssignedValue{&thirtyTwoLiteral, {}}; + + bool const ignoreMemory = MSizeFinder::containsMSize(_context.dialect, _ast); + UnusedStoreEliminator rse{ + _context.dialect, + functionSideEffects, + ControlFlowSideEffectsCollector{_context.dialect, _ast}.functionSideEffectsNamed(), + values, + ignoreMemory + }; + rse(_ast); + rse.changeUndecidedTo(State::Unused, Location::Memory); + rse.changeUndecidedTo(State::Used, Location::Storage); + rse.scheduleUnusedForDeletion(); + + StatementRemover remover(rse.m_pendingRemovals); + remover(_ast); +} + +void UnusedStoreEliminator::operator()(FunctionCall const& _functionCall) +{ + UnusedStoreBase::operator()(_functionCall); + + for (Operation const& op: operationsFromFunctionCall(_functionCall)) + applyOperation(op); + + ControlFlowSideEffects sideEffects; + if (auto builtin = m_dialect.builtin(_functionCall.functionName.name)) + sideEffects = builtin->controlFlowSideEffects; + else + sideEffects = m_controlFlowSideEffects.at(_functionCall.functionName.name); + + if (!sideEffects.canContinue) + { + changeUndecidedTo(State::Unused, Location::Memory); + changeUndecidedTo(sideEffects.canTerminate ? State::Used : State::Unused, Location::Storage); + } +} + +void UnusedStoreEliminator::operator()(FunctionDefinition const& _functionDefinition) +{ + ScopedSaveAndRestore storeOperations(m_storeOperations, {}); + UnusedStoreBase::operator()(_functionDefinition); +} + + +void UnusedStoreEliminator::operator()(Leave const&) +{ + changeUndecidedTo(State::Used); +} + +void UnusedStoreEliminator::visit(Statement const& _statement) +{ + using evmasm::Instruction; + + UnusedStoreBase::visit(_statement); + + auto const* exprStatement = get_if(&_statement); + if (!exprStatement) + return; + + FunctionCall const* funCall = get_if(&exprStatement->expression); + yulAssert(funCall); + optional instruction = toEVMInstruction(m_dialect, funCall->functionName.name); + if (!instruction) + return; + + if (!ranges::all_of(funCall->arguments, [](Expression const& _expr) -> bool { + return get_if(&_expr) || get_if(&_expr); + })) + return; + + // We determine if this is a store instruction without additional side-effects + // both by querying a combination of semantic information and by listing the instructions. + // This way the assert below should be triggered on any change. + using evmasm::SemanticInformation; + bool isStorageWrite = (*instruction == Instruction::SSTORE); + bool isMemoryWrite = + *instruction == Instruction::EXTCODECOPY || + *instruction == Instruction::CODECOPY || + *instruction == Instruction::CALLDATACOPY || + *instruction == Instruction::RETURNDATACOPY || + *instruction == Instruction::MSTORE || + *instruction == Instruction::MSTORE8; + bool isCandidateForRemoval = + SemanticInformation::otherState(*instruction) != SemanticInformation::Write && ( + SemanticInformation::storage(*instruction) == SemanticInformation::Write || + (!m_ignoreMemory && SemanticInformation::memory(*instruction) == SemanticInformation::Write) + ); + yulAssert(isCandidateForRemoval == (isStorageWrite || (!m_ignoreMemory && isMemoryWrite))); + if (isCandidateForRemoval) + { + m_stores[YulString{}].insert({&_statement, State::Undecided}); + vector operations = operationsFromFunctionCall(*funCall); + yulAssert(operations.size() == 1, ""); + m_storeOperations[&_statement] = move(operations.front()); + } +} + +void UnusedStoreEliminator::finalizeFunctionDefinition(FunctionDefinition const&) +{ + changeUndecidedTo(State::Used); + scheduleUnusedForDeletion(); +} + +vector UnusedStoreEliminator::operationsFromFunctionCall( + FunctionCall const& _functionCall +) const +{ + using evmasm::Instruction; + + YulString functionName = _functionCall.functionName.name; + SideEffects sideEffects; + if (BuiltinFunction const* f = m_dialect.builtin(functionName)) + sideEffects = f->sideEffects; + else + sideEffects = m_functionSideEffects.at(functionName); + + optional instruction = toEVMInstruction(m_dialect, functionName); + if (!instruction) + { + vector result; + // Unknown read is worse than unknown write. + if (sideEffects.memory != SideEffects::Effect::None) + result.emplace_back(Operation{Location::Memory, Effect::Read, {}, {}}); + if (sideEffects.storage != SideEffects::Effect::None) + result.emplace_back(Operation{Location::Storage, Effect::Read, {}, {}}); + return result; + } + + using evmasm::SemanticInformation; + + return util::applyMap( + SemanticInformation::readWriteOperations(*instruction), + [&](SemanticInformation::Operation const& _op) -> Operation + { + yulAssert(!(_op.lengthParameter && _op.lengthConstant)); + yulAssert(_op.effect != Effect::None); + Operation ourOp{_op.location, _op.effect, {}, {}}; + if (_op.startParameter) + ourOp.start = identifierNameIfSSA(_functionCall.arguments.at(*_op.startParameter)); + if (_op.lengthParameter) + ourOp.length = identifierNameIfSSA(_functionCall.arguments.at(*_op.lengthParameter)); + if (_op.lengthConstant) + switch (*_op.lengthConstant) + { + case 1: ourOp.length = YulString(one); break; + case 32: ourOp.length = YulString(thirtyTwo); break; + default: yulAssert(false); + } + return ourOp; + } + ); +} + +void UnusedStoreEliminator::applyOperation(UnusedStoreEliminator::Operation const& _operation) +{ + for (auto& [statement, state]: m_stores[YulString{}]) + if (state == State::Undecided) + { + Operation const& storeOperation = m_storeOperations.at(statement); + if (_operation.effect == Effect::Read && !knownUnrelated(storeOperation, _operation)) + state = State::Used; + else if (_operation.effect == Effect::Write && knownCovered(storeOperation, _operation)) + state = State::Unused; + } +} + +bool UnusedStoreEliminator::knownUnrelated( + UnusedStoreEliminator::Operation const& _op1, + UnusedStoreEliminator::Operation const& _op2 +) const +{ + KnowledgeBase knowledge(m_dialect, m_ssaValues); + + if (_op1.location != _op2.location) + return true; + if (_op1.location == Location::Storage) + { + if (_op1.start && _op2.start) + { + yulAssert( + _op1.length && + _op2.length && + knowledge.valueIfKnownConstant(*_op1.length) == 1 && + knowledge.valueIfKnownConstant(*_op2.length) == 1 + ); + return knowledge.knownToBeDifferent(*_op1.start, *_op2.start); + } + } + else + { + yulAssert(_op1.location == Location::Memory, ""); + if ( + (_op1.length && knowledge.knownToBeZero(*_op1.length)) || + (_op2.length && knowledge.knownToBeZero(*_op2.length)) + ) + return true; + + if (_op1.start && _op1.length && _op2.start) + { + optional length1 = knowledge.valueIfKnownConstant(*_op1.length); + optional start1 = knowledge.valueIfKnownConstant(*_op1.start); + optional start2 = knowledge.valueIfKnownConstant(*_op2.start); + if ( + (length1 && start1 && start2) && + *start1 + *length1 >= *start1 && // no overflow + *start1 + *length1 <= *start2 + ) + return true; + } + if (_op2.start && _op2.length && _op1.start) + { + optional length2 = knowledge.valueIfKnownConstant(*_op2.length); + optional start2 = knowledge.valueIfKnownConstant(*_op2.start); + optional start1 = knowledge.valueIfKnownConstant(*_op1.start); + if ( + (length2 && start2 && start1) && + *start2 + *length2 >= *start2 && // no overflow + *start2 + *length2 <= *start1 + ) + return true; + } + + if (_op1.start && _op1.length && _op2.start && _op2.length) + { + optional length1 = knowledge.valueIfKnownConstant(*_op1.length); + optional length2 = knowledge.valueIfKnownConstant(*_op2.length); + if ( + (length1 && *length1 <= 32) && + (length2 && *length2 <= 32) && + knowledge.knownToBeDifferentByAtLeast32(*_op1.start, *_op2.start) + ) + return true; + } + } + + return false; +} + +bool UnusedStoreEliminator::knownCovered( + UnusedStoreEliminator::Operation const& _covered, + UnusedStoreEliminator::Operation const& _covering +) const +{ + if (_covered.location != _covering.location) + return false; + if ( + (_covered.start && _covered.start == _covering.start) && + (_covered.length && _covered.length == _covering.length) + ) + return true; + if (_covered.location == Location::Memory) + { + KnowledgeBase knowledge(m_dialect, m_ssaValues); + + if (_covered.length && knowledge.knownToBeZero(*_covered.length)) + return true; + + // Condition (i = cover_i_ng, e = cover_e_d): + // i.start <= e.start && e.start + e.length <= i.start + i.length + if (!_covered.start || !_covering.start || !_covered.length || !_covering.length) + return false; + optional coveredLength = knowledge.valueIfKnownConstant(*_covered.length); + optional coveringLength = knowledge.valueIfKnownConstant(*_covering.length); + if (knowledge.knownToBeEqual(*_covered.start, *_covering.start)) + if (coveredLength && coveringLength && *coveredLength <= *coveringLength) + return true; + optional coveredStart = knowledge.valueIfKnownConstant(*_covered.start); + optional coveringStart = knowledge.valueIfKnownConstant(*_covering.start); + if (coveredStart && coveringStart && coveredLength && coveringLength) + if ( + *coveringStart <= *coveredStart && + *coveringStart + *coveringLength >= *coveringStart && // no overflow + *coveredStart + *coveredLength >= *coveredStart && // no overflow + *coveredStart + *coveredLength <= *coveringStart + *coveringLength + ) + return true; + + // TODO for this we probably need a non-overflow assumption as above. + // Condition (i = cover_i_ng, e = cover_e_d): + // i.start <= e.start && e.start + e.length <= i.start + i.length + } + return false; +} + +void UnusedStoreEliminator::changeUndecidedTo( + State _newState, + optional _onlyLocation) +{ + for (auto& [statement, state]: m_stores[YulString{}]) + if ( + state == State::Undecided && + (_onlyLocation == nullopt || *_onlyLocation == m_storeOperations.at(statement).location) + ) + state = _newState; +} + +optional UnusedStoreEliminator::identifierNameIfSSA(Expression const& _expression) const +{ + if (Identifier const* identifier = get_if(&_expression)) + if (m_ssaValues.count(identifier->name)) + return {identifier->name}; + return nullopt; +} + +void UnusedStoreEliminator::scheduleUnusedForDeletion() +{ + for (auto const& [statement, state]: m_stores[YulString{}]) + if (state == State::Unused) + m_pendingRemovals.insert(statement); +} diff --git a/libyul/optimiser/UnusedStoreEliminator.h b/libyul/optimiser/UnusedStoreEliminator.h new file mode 100644 index 000000000..dc3065e45 --- /dev/null +++ b/libyul/optimiser/UnusedStoreEliminator.h @@ -0,0 +1,119 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see . +*/ +// SPDX-License-Identifier: GPL-3.0 +/** + * Optimiser component that removes stores to memory and storage slots that are not used + * or overwritten later on. + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include + +#include +#include + +namespace solidity::yul +{ +struct Dialect; +struct AssignedValue; + +/** + * Optimizer component that removes sstore statements if they + * are overwritten in all code paths or never read from. + * + * The m_store member of UnusedStoreBase is only used with the empty yul string + * as key in the first dimension. + * + * Best run in SSA form. + * + * Prerequisite: Disambiguator, ForLoopInitRewriter. + */ +class UnusedStoreEliminator: public UnusedStoreBase +{ +public: + static constexpr char const* name{"UnusedStoreEliminator"}; + static void run(OptimiserStepContext& _context, Block& _ast); + + explicit UnusedStoreEliminator( + Dialect const& _dialect, + std::map const& _functionSideEffects, + std::map _controlFlowSideEffects, + std::map const& _ssaValues, + bool _ignoreMemory + ): + UnusedStoreBase(_dialect), + m_ignoreMemory(_ignoreMemory), + m_functionSideEffects(_functionSideEffects), + m_controlFlowSideEffects(_controlFlowSideEffects), + m_ssaValues(_ssaValues) + {} + + using UnusedStoreBase::operator(); + void operator()(FunctionCall const& _functionCall) override; + void operator()(FunctionDefinition const&) override; + void operator()(Leave const&) override; + + using UnusedStoreBase::visit; + void visit(Statement const& _statement) override; + + using Location = evmasm::SemanticInformation::Location; + using Effect = evmasm::SemanticInformation::Effect; + struct Operation + { + Location location; + Effect effect; + /// Start of affected area. Unknown if not provided. + std::optional start; + /// Length of affected area, unknown if not provided. + /// Unused for storage. + std::optional length; + }; + +private: + void shortcutNestedLoop(TrackedStores const&) override + { + // We might only need to do this for newly introduced stores in the loop. + changeUndecidedTo(State::Used); + } + void finalizeFunctionDefinition(FunctionDefinition const&) override; + + std::vector operationsFromFunctionCall(FunctionCall const& _functionCall) const; + void applyOperation(Operation const& _operation); + bool knownUnrelated(Operation const& _op1, Operation const& _op2) const; + bool knownCovered(Operation const& _covered, Operation const& _covering) const; + + void changeUndecidedTo(State _newState, std::optional _onlyLocation = std::nullopt); + void scheduleUnusedForDeletion(); + + std::optional identifierNameIfSSA(Expression const& _expression) const; + + bool const m_ignoreMemory; + std::map const& m_functionSideEffects; + std::map m_controlFlowSideEffects; + std::map const& m_ssaValues; + + std::map m_storeOperations; +}; + +} diff --git a/test/cmdlineTests/constant_optimizer_yul/output b/test/cmdlineTests/constant_optimizer_yul/output index 2a769811a..ae0b7a0f6 100644 --- a/test/cmdlineTests/constant_optimizer_yul/output +++ b/test/cmdlineTests/constant_optimizer_yul/output @@ -27,7 +27,6 @@ object "C_12" { code { { /// @src 0:61:418 "contract C {..." - mstore(64, memoryguard(0x80)) if callvalue() { revert(0, 0) } /// @src 0:279:410 "assembly {..." sstore(0, 0x1000000000000000000000000000000000000000000000) diff --git a/test/cmdlineTests/debug_info_in_yul_and_evm_asm_print_all/output b/test/cmdlineTests/debug_info_in_yul_and_evm_asm_print_all/output index 7775ff69c..3b0e1d3ba 100644 --- a/test/cmdlineTests/debug_info_in_yul_and_evm_asm_print_all/output +++ b/test/cmdlineTests/debug_info_in_yul_and_evm_asm_print_all/output @@ -201,16 +201,14 @@ object "C_6" { code { { /// @src 0:60:101 "contract C {..." - let _1 := memoryguard(0x80) - mstore(64, _1) if iszero(lt(calldatasize(), 4)) { - let _2 := 0 - if eq(0x26121ff0, shr(224, calldataload(_2))) + let _1 := 0 + if eq(0x26121ff0, shr(224, calldataload(_1))) { - if callvalue() { revert(_2, _2) } - if slt(add(calldatasize(), not(3)), _2) { revert(_2, _2) } - return(_1, _2) + if callvalue() { revert(_1, _1) } + if slt(add(calldatasize(), not(3)), _1) { revert(_1, _1) } + return(memoryguard(0x80), _1) } } revert(0, 0) diff --git a/test/cmdlineTests/debug_info_in_yul_and_evm_asm_print_location_only/output b/test/cmdlineTests/debug_info_in_yul_and_evm_asm_print_location_only/output index 35f680d92..94d748169 100644 --- a/test/cmdlineTests/debug_info_in_yul_and_evm_asm_print_location_only/output +++ b/test/cmdlineTests/debug_info_in_yul_and_evm_asm_print_location_only/output @@ -200,16 +200,14 @@ object "C_6" { code { { /// @src 0:60:101 - let _1 := memoryguard(0x80) - mstore(64, _1) if iszero(lt(calldatasize(), 4)) { - let _2 := 0 - if eq(0x26121ff0, shr(224, calldataload(_2))) + let _1 := 0 + if eq(0x26121ff0, shr(224, calldataload(_1))) { - if callvalue() { revert(_2, _2) } - if slt(add(calldatasize(), not(3)), _2) { revert(_2, _2) } - return(_1, _2) + if callvalue() { revert(_1, _1) } + if slt(add(calldatasize(), not(3)), _1) { revert(_1, _1) } + return(memoryguard(0x80), _1) } } revert(0, 0) diff --git a/test/cmdlineTests/debug_info_in_yul_and_evm_asm_print_none/output b/test/cmdlineTests/debug_info_in_yul_and_evm_asm_print_none/output index 93fad0421..706b8f773 100644 --- a/test/cmdlineTests/debug_info_in_yul_and_evm_asm_print_none/output +++ b/test/cmdlineTests/debug_info_in_yul_and_evm_asm_print_none/output @@ -189,16 +189,14 @@ object "C_6" { object "C_6_deployed" { code { { - let _1 := memoryguard(0x80) - mstore(64, _1) if iszero(lt(calldatasize(), 4)) { - let _2 := 0 - if eq(0x26121ff0, shr(224, calldataload(_2))) + let _1 := 0 + if eq(0x26121ff0, shr(224, calldataload(_1))) { - if callvalue() { revert(_2, _2) } - if slt(add(calldatasize(), not(3)), _2) { revert(_2, _2) } - return(_1, _2) + if callvalue() { revert(_1, _1) } + if slt(add(calldatasize(), not(3)), _1) { revert(_1, _1) } + return(memoryguard(0x80), _1) } } revert(0, 0) diff --git a/test/cmdlineTests/debug_info_in_yul_snippet_escaping/output b/test/cmdlineTests/debug_info_in_yul_snippet_escaping/output index 82a74384e..1408b6021 100644 --- a/test/cmdlineTests/debug_info_in_yul_snippet_escaping/output +++ b/test/cmdlineTests/debug_info_in_yul_snippet_escaping/output @@ -95,7 +95,6 @@ object "C_2" { code { { /// @src 0:265:278 "contract C {}" - mstore(64, memoryguard(0x80)) revert(0, 0) } } @@ -559,7 +558,6 @@ object "D_27" { code { { /// @src 0:265:278 "contract C {}" - mstore(64, memoryguard(0x80)) revert(0, 0) } } diff --git a/test/cmdlineTests/ir_compiler_inheritance_nosubobjects/output b/test/cmdlineTests/ir_compiler_inheritance_nosubobjects/output index 330e208f4..5246a50ee 100644 --- a/test/cmdlineTests/ir_compiler_inheritance_nosubobjects/output +++ b/test/cmdlineTests/ir_compiler_inheritance_nosubobjects/output @@ -24,7 +24,6 @@ object "C_7" { code { { /// @src 0:82:117 "contract C {..." - mstore(64, memoryguard(0x80)) revert(0, 0) } } @@ -58,7 +57,6 @@ object "D_10" { code { { /// @src 0:118:137 "contract D is C {..." - mstore(64, memoryguard(0x80)) revert(0, 0) } } diff --git a/test/cmdlineTests/ir_compiler_subobjects/output b/test/cmdlineTests/ir_compiler_subobjects/output index fbedf38db..80d90aac5 100644 --- a/test/cmdlineTests/ir_compiler_subobjects/output +++ b/test/cmdlineTests/ir_compiler_subobjects/output @@ -24,7 +24,6 @@ object "C_3" { code { { /// @src 0:82:95 "contract C {}" - mstore(64, memoryguard(0x80)) revert(0, 0) } } @@ -110,7 +109,6 @@ object "D_16" { code { { /// @src 0:82:95 "contract C {}" - mstore(64, memoryguard(0x80)) revert(0, 0) } } diff --git a/test/cmdlineTests/ir_with_assembly_no_memoryguard_creation/output b/test/cmdlineTests/ir_with_assembly_no_memoryguard_creation/output index d9b769a12..90c7ddf65 100644 --- a/test/cmdlineTests/ir_with_assembly_no_memoryguard_creation/output +++ b/test/cmdlineTests/ir_with_assembly_no_memoryguard_creation/output @@ -11,11 +11,7 @@ object "D_12" { code { { /// @src 0:82:175 "contract D {..." - mstore(64, 128) if callvalue() { revert(0, 0) } - /// @src 0:115:139 "assembly { mstore(0,0) }" - mstore(0, 0) - /// @src 0:82:175 "contract D {..." let _1 := datasize("D_12_deployed") codecopy(128, dataoffset("D_12_deployed"), _1) return(128, _1) @@ -26,16 +22,14 @@ object "D_12" { code { { /// @src 0:82:175 "contract D {..." - let _1 := memoryguard(0x80) - mstore(64, _1) if iszero(lt(calldatasize(), 4)) { - let _2 := 0 - if eq(0x26121ff0, shr(224, calldataload(_2))) + let _1 := 0 + if eq(0x26121ff0, shr(224, calldataload(_1))) { - if callvalue() { revert(_2, _2) } - if slt(add(calldatasize(), not(3)), _2) { revert(_2, _2) } - return(_1, _2) + if callvalue() { revert(_1, _1) } + if slt(add(calldatasize(), not(3)), _1) { revert(_1, _1) } + return(memoryguard(0x80), _1) } } revert(0, 0) diff --git a/test/cmdlineTests/ir_with_assembly_no_memoryguard_runtime/output b/test/cmdlineTests/ir_with_assembly_no_memoryguard_runtime/output index 9a07c7861..7738519c4 100644 --- a/test/cmdlineTests/ir_with_assembly_no_memoryguard_runtime/output +++ b/test/cmdlineTests/ir_with_assembly_no_memoryguard_runtime/output @@ -24,7 +24,6 @@ object "D_8" { code { { /// @src 0:82:166 "contract D {..." - mstore(64, 128) if iszero(lt(calldatasize(), 4)) { let _1 := 0 @@ -32,8 +31,6 @@ object "D_8" { { if callvalue() { revert(_1, _1) } if slt(add(calldatasize(), not(3)), _1) { revert(_1, _1) } - /// @src 0:134:158 "assembly { mstore(0,0) }" - mstore(/** @src 0:82:166 "contract D {..." */ _1, _1) return(128, _1) } } diff --git a/test/cmdlineTests/keccak_optimization_deploy_code/output b/test/cmdlineTests/keccak_optimization_deploy_code/output index 4abb046f6..b70a029fc 100644 --- a/test/cmdlineTests/keccak_optimization_deploy_code/output +++ b/test/cmdlineTests/keccak_optimization_deploy_code/output @@ -11,7 +11,6 @@ object "C_12" { code { { /// @src 0:62:463 "contract C {..." - mstore(64, 128) if callvalue() { revert(0, 0) } /// @src 0:103:275 "assembly {..." mstore(0, 100) @@ -27,10 +26,8 @@ object "C_12" { code { { /// @src 0:62:463 "contract C {..." - mstore(64, 128) if callvalue() { revert(0, 0) } /// @src 0:317:454 "assembly {..." - mstore(0, 100) sstore(0, 17385872270140913825666367956517731270094621555228275961425792378517567244498) /// @src 0:62:463 "contract C {..." stop() diff --git a/test/cmdlineTests/keccak_optimization_low_runs/output b/test/cmdlineTests/keccak_optimization_low_runs/output index f5df14027..691e37145 100644 --- a/test/cmdlineTests/keccak_optimization_low_runs/output +++ b/test/cmdlineTests/keccak_optimization_low_runs/output @@ -24,7 +24,6 @@ object "C_7" { code { { /// @src 0:62:285 "contract C {..." - mstore(64, 128) if callvalue() { revert(0, 0) } /// @src 0:109:277 "assembly {..." mstore(0, 100) diff --git a/test/cmdlineTests/optimizer_user_yul/output b/test/cmdlineTests/optimizer_user_yul/output index f6e7705c7..689e82ddb 100644 --- a/test/cmdlineTests/optimizer_user_yul/output +++ b/test/cmdlineTests/optimizer_user_yul/output @@ -58,10 +58,9 @@ tag_6: /* "optimizer_user_yul/input.sol":384:392 sload(5) */ dup1 /* "optimizer_user_yul/input.sol":376:509 for { } sload(5) { } {... */ - tag_8 + iszero + tag_6 jumpi - jump(tag_6) -tag_8: /* "optimizer_user_yul/input.sol":380:383 { } */ pop /* "optimizer_user_yul/input.sol":340:513 {... */ diff --git a/test/cmdlineTests/standard_debug_info_in_evm_asm_via_ir_location/output.json b/test/cmdlineTests/standard_debug_info_in_evm_asm_via_ir_location/output.json index 238934a3f..f7d61a7b1 100644 --- a/test/cmdlineTests/standard_debug_info_in_evm_asm_via_ir_location/output.json +++ b/test/cmdlineTests/standard_debug_info_in_evm_asm_via_ir_location/output.json @@ -1,8 +1,5 @@ {"contracts":{"C":{"C":{"evm":{"assembly":" /* \"C\":79:428 contract C... */ 0xa0 - dup1 - 0x40 - mstore jumpi(tag_6, callvalue) 0x1f bytecodeSize @@ -438,9 +435,6 @@ sub_0: assembly { } "}}},"D":{"D":{"evm":{"assembly":" /* \"D\":91:166 contract D is C(3)... */ 0xa0 - dup1 - 0x40 - mstore jumpi(tag_6, callvalue) 0x1f bytecodeSize @@ -514,13 +508,8 @@ tag_4: tag_1: /* \"C\":147:149 42 */ mstore(0x80, 0x2a) - /* \"D\":107:108 3 */ - 0x03 - /* \"C\":203:219 stateVar = _init */ - 0x00 - /* \"D\":91:166 contract D is C(3)... */ - sstore sub(shl(0xff, 0x01), 0x04) + /* \"D\":91:166 contract D is C(3)... */ dup2 sgt 0x01 @@ -531,9 +520,7 @@ tag_1: 0x03 /* \"D\":91:166 contract D is C(3)... */ add - /* \"C\":203:219 stateVar = _init */ 0x00 - /* \"D\":91:166 contract D is C(3)... */ sstore /* \"D\":113:164 constructor(int _init2)... */ jump\t// out @@ -541,17 +528,9 @@ tag_1: tag_9: pop pop - shl(0xe0, 0x4e487b71) - /* \"C\":203:219 stateVar = _init */ - 0x00 - /* \"D\":91:166 contract D is C(3)... */ - mstore + mstore(0x00, shl(0xe0, 0x4e487b71)) mstore(0x04, 0x11) - 0x24 - /* \"C\":203:219 stateVar = _init */ - 0x00 - /* \"D\":91:166 contract D is C(3)... */ - revert + revert(0x00, 0x24) stop sub_0: assembly { diff --git a/test/cmdlineTests/standard_debug_info_in_yul_and_evm_asm_print_all/output.json b/test/cmdlineTests/standard_debug_info_in_yul_and_evm_asm_print_all/output.json index 16236251d..44c143b71 100644 --- a/test/cmdlineTests/standard_debug_info_in_yul_and_evm_asm_print_all/output.json +++ b/test/cmdlineTests/standard_debug_info_in_yul_and_evm_asm_print_all/output.json @@ -206,16 +206,14 @@ object \"C_6\" { code { { /// @src 0:60:101 \"contract C {...\" - let _1 := memoryguard(0x80) - mstore(64, _1) if iszero(lt(calldatasize(), 4)) { - let _2 := 0 - if eq(0x26121ff0, shr(224, calldataload(_2))) + let _1 := 0 + if eq(0x26121ff0, shr(224, calldataload(_1))) { - if callvalue() { revert(_2, _2) } - if slt(add(calldatasize(), not(3)), _2) { revert(_2, _2) } - return(_1, _2) + if callvalue() { revert(_1, _1) } + if slt(add(calldatasize(), not(3)), _1) { revert(_1, _1) } + return(memoryguard(0x80), _1) } } revert(0, 0) diff --git a/test/cmdlineTests/standard_debug_info_in_yul_and_evm_asm_print_location_only/output.json b/test/cmdlineTests/standard_debug_info_in_yul_and_evm_asm_print_location_only/output.json index d017c8e9c..8dad4c42e 100644 --- a/test/cmdlineTests/standard_debug_info_in_yul_and_evm_asm_print_location_only/output.json +++ b/test/cmdlineTests/standard_debug_info_in_yul_and_evm_asm_print_location_only/output.json @@ -205,16 +205,14 @@ object \"C_6\" { code { { /// @src 0:60:101 - let _1 := memoryguard(0x80) - mstore(64, _1) if iszero(lt(calldatasize(), 4)) { - let _2 := 0 - if eq(0x26121ff0, shr(224, calldataload(_2))) + let _1 := 0 + if eq(0x26121ff0, shr(224, calldataload(_1))) { - if callvalue() { revert(_2, _2) } - if slt(add(calldatasize(), not(3)), _2) { revert(_2, _2) } - return(_1, _2) + if callvalue() { revert(_1, _1) } + if slt(add(calldatasize(), not(3)), _1) { revert(_1, _1) } + return(memoryguard(0x80), _1) } } revert(0, 0) diff --git a/test/cmdlineTests/standard_debug_info_in_yul_and_evm_asm_print_none/output.json b/test/cmdlineTests/standard_debug_info_in_yul_and_evm_asm_print_none/output.json index afe07fad9..1675f7ec5 100644 --- a/test/cmdlineTests/standard_debug_info_in_yul_and_evm_asm_print_none/output.json +++ b/test/cmdlineTests/standard_debug_info_in_yul_and_evm_asm_print_none/output.json @@ -194,16 +194,14 @@ object \"C_6\" { object \"C_6_deployed\" { code { { - let _1 := memoryguard(0x80) - mstore(64, _1) if iszero(lt(calldatasize(), 4)) { - let _2 := 0 - if eq(0x26121ff0, shr(224, calldataload(_2))) + let _1 := 0 + if eq(0x26121ff0, shr(224, calldataload(_1))) { - if callvalue() { revert(_2, _2) } - if slt(add(calldatasize(), not(3)), _2) { revert(_2, _2) } - return(_1, _2) + if callvalue() { revert(_1, _1) } + if slt(add(calldatasize(), not(3)), _1) { revert(_1, _1) } + return(memoryguard(0x80), _1) } } revert(0, 0) diff --git a/test/cmdlineTests/standard_debug_info_in_yul_location/output.json b/test/cmdlineTests/standard_debug_info_in_yul_location/output.json index f593301bc..f21722a63 100644 --- a/test/cmdlineTests/standard_debug_info_in_yul_location/output.json +++ b/test/cmdlineTests/standard_debug_info_in_yul_location/output.json @@ -622,7 +622,6 @@ object \"C_54\" { { /// @src 0:79:435 \"contract C...\" let _1 := memoryguard(0xa0) - mstore(64, _1) if callvalue() { revert(0, 0) } let programSize := datasize(\"C_54\") let argSize := sub(codesize(), programSize) @@ -1469,7 +1468,6 @@ object \"D_72\" { { /// @src 1:91:166 \"contract D is C(3)...\" let _1 := memoryguard(0xa0) - mstore(64, _1) if callvalue() { revert(0, 0) } let programSize := datasize(\"D_72\") let argSize := sub(codesize(), programSize) @@ -1500,15 +1498,13 @@ object \"D_72\" { /// @src 0:154:156 \"42\" mstore(128, 0x2a) /// @src 1:91:166 \"contract D is C(3)...\" - sstore(/** @src 0:210:226 \"stateVar = _init\" */ 0x00, /** @src 1:107:108 \"3\" */ 0x03) - /// @src 1:91:166 \"contract D is C(3)...\" if and(1, sgt(var_init2, sub(shl(255, 1), 4))) { - mstore(/** @src 0:210:226 \"stateVar = _init\" */ 0x00, /** @src 1:91:166 \"contract D is C(3)...\" */ shl(224, 0x4e487b71)) + mstore(0, shl(224, 0x4e487b71)) mstore(4, 0x11) - revert(/** @src 0:210:226 \"stateVar = _init\" */ 0x00, /** @src 1:91:166 \"contract D is C(3)...\" */ 0x24) + revert(0, 0x24) } - sstore(/** @src 0:210:226 \"stateVar = _init\" */ 0x00, /** @src 1:91:166 \"contract D is C(3)...\" */ add(/** @src 1:107:108 \"3\" */ 0x03, /** @src 1:91:166 \"contract D is C(3)...\" */ var_init2)) + sstore(/** @src -1:-1:-1 */ 0, /** @src 1:91:166 \"contract D is C(3)...\" */ add(/** @src 1:107:108 \"3\" */ 0x03, /** @src 1:91:166 \"contract D is C(3)...\" */ var_init2)) } } /// @use-src 0:\"C\", 1:\"D\" diff --git a/test/cmdlineTests/viair_subobject_optimization/output b/test/cmdlineTests/viair_subobject_optimization/output index 8b5666b37..7dec204b1 100644 --- a/test/cmdlineTests/viair_subobject_optimization/output +++ b/test/cmdlineTests/viair_subobject_optimization/output @@ -3,9 +3,6 @@ EVM assembly: /* "viair_subobject_optimization/input.sol":61:668 contract C {... */ 0x80 - dup1 - 0x40 - mstore jumpi(tag_6, callvalue) 0x1f bytecodeSize @@ -86,7 +83,6 @@ stop sub_0: assembly { /* "viair_subobject_optimization/input.sol":61:668 contract C {... */ - mstore(0x40, 0x80) 0x00 dup1 revert @@ -120,9 +116,6 @@ stop sub_0: assembly { /* "viair_subobject_optimization/input.sol":669:772 contract D {... */ 0x80 - dup1 - 0x40 - mstore jumpi(tag_2, iszero(lt(calldatasize, 0x04))) tag_3: pop @@ -283,9 +276,6 @@ sub_0: assembly { sub_0: assembly { /* "viair_subobject_optimization/input.sol":61:668 contract C {... */ 0x80 - dup1 - 0x40 - mstore jumpi(tag_6, callvalue) 0x1f bytecodeSize @@ -366,7 +356,6 @@ sub_0: assembly { sub_0: assembly { /* "viair_subobject_optimization/input.sol":61:668 contract C {... */ - mstore(0x40, 0x80) 0x00 dup1 revert diff --git a/test/cmdlineTests/viair_subobjects/output b/test/cmdlineTests/viair_subobjects/output index 4b388665c..aea2013ec 100644 --- a/test/cmdlineTests/viair_subobjects/output +++ b/test/cmdlineTests/viair_subobjects/output @@ -30,7 +30,6 @@ object "C_3" { code { { /// @src 0:82:95 "contract C {}" - mstore(64, memoryguard(0x80)) revert(0, 0) } } @@ -122,7 +121,6 @@ object "D_16" { code { { /// @src 0:82:95 "contract C {}" - mstore(64, memoryguard(0x80)) revert(0, 0) } } diff --git a/test/externalTests.sh b/test/externalTests.sh index b3b46460b..2c4c6f76c 100755 --- a/test/externalTests.sh +++ b/test/externalTests.sh @@ -39,7 +39,6 @@ printTask "Running external tests..." "{$REPO_ROOT}/test/externalTests/zeppelin.sh" "$@" "{$REPO_ROOT}/test/externalTests/gnosis.sh" "$@" -"{$REPO_ROOT}/test/externalTests/gnosis-v2.sh" "$@" "{$REPO_ROOT}/test/externalTests/colony.sh" "$@" "{$REPO_ROOT}/test/externalTests/ens.sh" "$@" "{$REPO_ROOT}/test/externalTests/trident.sh" "$@" diff --git a/test/externalTests/common.sh b/test/externalTests/common.sh index e4e1e3adf..9c68c8828 100644 --- a/test/externalTests/common.sh +++ b/test/externalTests/common.sh @@ -233,7 +233,6 @@ function force_truffle_compiler_settings function name_hardhat_default_export { local config_file="$1" - local config_var_name="$2" local import="import {HardhatUserConfig} from 'hardhat/types';" local config="const config: HardhatUserConfig = {" @@ -241,6 +240,29 @@ function name_hardhat_default_export echo "export default config;" >> "$config_file" } +function force_hardhat_timeout +{ + local config_file="$1" + local config_var_name="$2" + local new_timeout="$3" + + printLog "Configuring Hardhat..." + echo "-------------------------------------" + echo "Timeout: ${new_timeout}" + echo "-------------------------------------" + + if [[ $config_file == *\.js ]]; then + [[ $config_var_name == "" ]] || assertFail + echo "module.exports.mocha = module.exports.mocha || {timeout: ${new_timeout}}" + echo "module.exports.mocha.timeout = ${new_timeout}" + else + [[ $config_file == *\.ts ]] || assertFail + [[ $config_var_name != "" ]] || assertFail + echo "${config_var_name}.mocha = ${config_var_name}.mocha ?? {timeout: ${new_timeout}};" + echo "${config_var_name}.mocha!.timeout = ${new_timeout}" + fi >> "$config_file" +} + function force_hardhat_compiler_binary { local config_file="$1" diff --git a/test/externalTests/euler.sh b/test/externalTests/euler.sh index b3b505051..6a73f00e5 100755 --- a/test/externalTests/euler.sh +++ b/test/externalTests/euler.sh @@ -63,6 +63,8 @@ function euler_test force_hardhat_compiler_binary "$config_file" "$BINARY_TYPE" "$BINARY_PATH" force_hardhat_compiler_settings "$config_file" "$(first_word "$SELECTED_PRESETS")" force_hardhat_unlimited_contract_size "$config_file" + # Workaround for the timeout that's too short for unoptimized code (https://github.com/ethereum/solidity/pull/12765) + force_hardhat_timeout "$config_file" "" 100000 npm install replace_version_pragmas diff --git a/test/externalTests/gnosis-v2.sh b/test/externalTests/gnosis-v2.sh deleted file mode 100755 index 6b0915b6a..000000000 --- a/test/externalTests/gnosis-v2.sh +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env bash - -# ------------------------------------------------------------------------------ -# This file is part of solidity. -# -# solidity is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# solidity is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with solidity. If not, see -# -# (c) 2020 solidity contributors. -#------------------------------------------------------------------------------ - -set -e - -source scripts/common.sh -source test/externalTests/common.sh - -REPO_ROOT=$(realpath "$(dirname "$0")/../..") - -verify_input "$@" -BINARY_TYPE="$1" -BINARY_PATH="$2" -SELECTED_PRESETS="$3" - -function compile_fn { npx truffle compile; } -function test_fn { npm test; } - -function gnosis_safe_test -{ - local repo="https://github.com/solidity-external-tests/safe-contracts.git" - local ref_type=branch - local ref="v2_080" - local config_file="truffle-config.js" - - local compile_only_presets=( - legacy-no-optimize # Compiles but migrations run out of gas: "Error: while migrating GnosisSafe: Returned error: base fee exceeds gas limit" - ) - local settings_presets=( - "${compile_only_presets[@]}" - #ir-no-optimize # Compilation fails with "YulException: Variable var_call_430_mpos is 1 slot(s) too deep inside the stack." - #ir-optimize-evm-only # Compilation fails with "YulException: Variable var_call_430_mpos is 1 slot(s) too deep inside the stack." - ir-optimize-evm+yul - legacy-optimize-evm-only - legacy-optimize-evm+yul - ) - - [[ $SELECTED_PRESETS != "" ]] || SELECTED_PRESETS=$(circleci_select_steps_multiarg "${settings_presets[@]}") - print_presets_or_exit "$SELECTED_PRESETS" - - setup_solc "$DIR" "$BINARY_TYPE" "$BINARY_PATH" - download_project "$repo" "$ref_type" "$ref" "$DIR" - [[ $BINARY_TYPE == native ]] && replace_global_solc "$BINARY_PATH" - - sed -i 's|github:gnosis/mock-contract#sol_0_5_0|github:solidity-external-tests/mock-contract#master_080|g' package.json - sed -i -E 's|"@gnosis.pm/util-contracts": "[^"]+"|"@gnosis.pm/util-contracts": "github:solidity-external-tests/util-contracts#solc-7_080"|g' package.json - - neutralize_package_lock - neutralize_package_json_hooks - force_truffle_compiler_settings "$config_file" "$BINARY_TYPE" "${DIR}/solc/dist" "$(first_word "$SELECTED_PRESETS")" - npm install --package-lock - npm install eth-gas-reporter - - replace_version_pragmas - [[ $BINARY_TYPE == solcjs ]] && force_solc_modules "${DIR}/solc/dist" - - for preset in $SELECTED_PRESETS; do - truffle_run_test "$config_file" "$BINARY_TYPE" "${DIR}/solc/dist" "$preset" "${compile_only_presets[*]}" compile_fn test_fn - store_benchmark_report truffle gnosis2 "$repo" "$preset" - done -} - -external_test Gnosis-Safe-V2 gnosis_safe_test diff --git a/test/externalTests/gnosis.sh b/test/externalTests/gnosis.sh index 82d1892f2..ec09257fb 100755 --- a/test/externalTests/gnosis.sh +++ b/test/externalTests/gnosis.sh @@ -31,24 +31,26 @@ BINARY_TYPE="$1" BINARY_PATH="$2" SELECTED_PRESETS="$3" -function compile_fn { npx truffle compile; } +function compile_fn { npm run build; } function test_fn { npm test; } function gnosis_safe_test { - local repo="https://github.com/solidity-external-tests/safe-contracts.git" + local repo="https://github.com/gnosis/safe-contracts.git" local ref_type=branch - local ref="development_080" - local config_file="truffle-config.js" + local ref=main + local config_file="hardhat.config.ts" + local config_var=userConfig - local compile_only_presets=() + local compile_only_presets=( + ir-optimize-evm+yul # Compiles but tests fail. See https://github.com/nomiclabs/hardhat/issues/2115 + ) local settings_presets=( "${compile_only_presets[@]}" #ir-no-optimize # Compilation fails with "YulException: Variable var_call_430_mpos is 1 slot(s) too deep inside the stack." #ir-optimize-evm-only # Compilation fails with "YulException: Variable var_call_430_mpos is 1 slot(s) too deep inside the stack." - ir-optimize-evm+yul - #legacy-no-optimize # Compilation fails with "Stack too deep" error - #legacy-optimize-evm-only # Compilation fails with "Stack too deep" error + legacy-no-optimize + legacy-optimize-evm-only legacy-optimize-evm+yul ) @@ -59,20 +61,28 @@ function gnosis_safe_test download_project "$repo" "$ref_type" "$ref" "$DIR" [[ $BINARY_TYPE == native ]] && replace_global_solc "$BINARY_PATH" - sed -i 's|github:gnosis/mock-contract#sol_0_5_0|github:solidity-external-tests/mock-contract#master_080|g' package.json + # NOTE: The patterns below intentionally have hard-coded versions. + # When the upstream updates them, there's a chance we can just remove the regex. + sed -i 's|"@gnosis\.pm/mock-contract": "\^4\.0\.0"|"@gnosis.pm/mock-contract": "github:solidity-external-tests/mock-contract#master_080"|g' package.json + sed -i 's|"@openzeppelin/contracts": "\^3\.4\.0"|"@openzeppelin/contracts": "^4.0.0"|g' package.json + + # Disable two tests failing due to Hardhat's heuristics not yet updated to handle solc 0.8.10. + # TODO: Remove this when Hardhat implements them (https://github.com/nomiclabs/hardhat/issues/2051). + sed -i "s|\(it\)\(('should revert if called directly', async () => {\)|\1.skip\2|g" test/handlers/CompatibilityFallbackHandler.spec.ts neutralize_package_lock neutralize_package_json_hooks - force_truffle_compiler_settings "$config_file" "$BINARY_TYPE" "${DIR}/solc/dist" "$(first_word "$SELECTED_PRESETS")" - npm install --package-lock - npm install eth-gas-reporter + force_hardhat_compiler_binary "$config_file" "$BINARY_TYPE" "$BINARY_PATH" + force_hardhat_compiler_settings "$config_file" "$(first_word "$SELECTED_PRESETS")" "$config_var" + npm install + npm install hardhat-gas-reporter replace_version_pragmas [[ $BINARY_TYPE == solcjs ]] && force_solc_modules "${DIR}/solc/dist" for preset in $SELECTED_PRESETS; do - truffle_run_test "$config_file" "$BINARY_TYPE" "${DIR}/solc/dist" "$preset" "${compile_only_presets[*]}" compile_fn test_fn - store_benchmark_report truffle gnosis "$repo" "$preset" + hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var" + store_benchmark_report hardhat gnosis "$repo" "$preset" done } diff --git a/test/formal/redundant_store_unrelated.py b/test/formal/redundant_store_unrelated.py new file mode 100644 index 000000000..2961d0099 --- /dev/null +++ b/test/formal/redundant_store_unrelated.py @@ -0,0 +1,63 @@ +import sys +from z3 import Solver, Int, unsat + +""" +Tests that the conditions inside RedundantStoreEliminator::knownUnrelated +only return "unrelated" incorrectly if one of the operation reverts +due to large memory access. +""" + +n_bits = 256 + +solver = Solver() +solver.set("timeout", 60000) + +def restrict(x): + solver.add(x >= 0) + solver.add(x < 2**n_bits) + +def restrictedInt(x): + var = Int(x) + restrict(var) + return var + +start1 = restrictedInt('start1') +length1 = restrictedInt('length1') +start2 = restrictedInt('start2') +length2 = restrictedInt('length2') + +k = Int('k') +diff = Int('diff') +solver.add(diff == start2 - start1 + k * 2**n_bits) +restrict(diff) +# diff is the result of sub(start2, start1) in EVM + +# These are the conditions in the code. +solver.add(diff >= length1) +solver.add(diff <= 2**(n_bits-1)) + +# We check that the two conditions are conflicting: +# - overlap +# - start1 is small + +# Overlap: +# x is a potential point where the memory operations +# overlap. +# Note that we do not use wrapping arithmetic +# here, because it is not done in the EVM either. +# For example calldatacopy(2**256 - 2, 0, 10) +# (copy 10 bytes from calldata position zero to memory +# position 2**256 - 2) would not write to memory position +# zero either. +x = Int('x') +solver.add(start1 <= x) +solver.add(x < start1 + length1) +solver.add(start2 <= x) +solver.add(x < start2 + length2) + +# start1 is "small": +solver.add(start1 < 2**(n_bits-1)) + +if solver.check() != unsat: + print("Expected unsat but got something else") + sys.exit(1) diff --git a/test/libsolidity/semanticTests/abiEncoderV1/abi_decode_v2_storage.sol b/test/libsolidity/semanticTests/abiEncoderV1/abi_decode_v2_storage.sol index 06f9bcbbf..302e878d1 100644 --- a/test/libsolidity/semanticTests/abiEncoderV1/abi_decode_v2_storage.sol +++ b/test/libsolidity/semanticTests/abiEncoderV1/abi_decode_v2_storage.sol @@ -25,5 +25,5 @@ contract C { // ---- // f() -> 0x20, 0x8, 0x40, 0x3, 0x9, 0xa, 0xb // gas irOptimized: 203312 -// gas legacy: 206084 -// gas legacyOptimized: 203068 +// gas legacy: 206075 +// gas legacyOptimized: 203059 diff --git a/test/libsolidity/semanticTests/abiEncoderV1/abi_encode_calldata_slice.sol b/test/libsolidity/semanticTests/abiEncoderV1/abi_encode_calldata_slice.sol index c386cf3e8..5c7cc1cd5 100644 --- a/test/libsolidity/semanticTests/abiEncoderV1/abi_encode_calldata_slice.sol +++ b/test/libsolidity/semanticTests/abiEncoderV1/abi_encode_calldata_slice.sol @@ -61,9 +61,9 @@ contract C { // ---- // test_bytes() -> // gas irOptimized: 371919 -// gas legacy: 418955 -// gas legacyOptimized: 326783 +// gas legacy: 416585 +// gas legacyOptimized: 322043 // test_uint256() -> // gas irOptimized: 523001 -// gas legacy: 586784 -// gas legacyOptimized: 451529 +// gas legacy: 583100 +// gas legacyOptimized: 444161 diff --git a/test/libsolidity/semanticTests/abiEncoderV2/abi_encode_calldata_slice.sol b/test/libsolidity/semanticTests/abiEncoderV2/abi_encode_calldata_slice.sol index 9deed97f1..6c6336689 100644 --- a/test/libsolidity/semanticTests/abiEncoderV2/abi_encode_calldata_slice.sol +++ b/test/libsolidity/semanticTests/abiEncoderV2/abi_encode_calldata_slice.sol @@ -62,9 +62,9 @@ contract C { // ---- // test_bytes() -> // gas irOptimized: 371919 -// gas legacy: 418955 -// gas legacyOptimized: 326783 +// gas legacy: 416585 +// gas legacyOptimized: 322043 // test_uint256() -> // gas irOptimized: 523001 -// gas legacy: 586784 -// gas legacyOptimized: 451529 +// gas legacy: 583100 +// gas legacyOptimized: 444161 diff --git a/test/libsolidity/semanticTests/abiEncoderV2/calldata_array.sol b/test/libsolidity/semanticTests/abiEncoderV2/calldata_array.sol index cf5958d45..8f42fe5f7 100644 --- a/test/libsolidity/semanticTests/abiEncoderV2/calldata_array.sol +++ b/test/libsolidity/semanticTests/abiEncoderV2/calldata_array.sol @@ -22,5 +22,5 @@ contract C { // f(uint256[][1]): 32, 32, 1, 42 -> true // f(uint256[][1]): 32, 32, 8, 421, 422, 423, 424, 425, 426, 427, 428 -> true // gas irOptimized: 171842 -// gas legacy: 141644 -// gas legacyOptimized: 121532 +// gas legacy: 140672 +// gas legacyOptimized: 119588 diff --git a/test/libsolidity/semanticTests/abiencodedecode/abi_decode_simple_storage.sol b/test/libsolidity/semanticTests/abiencodedecode/abi_decode_simple_storage.sol index b6c6ad5f0..027ae4e16 100644 --- a/test/libsolidity/semanticTests/abiencodedecode/abi_decode_simple_storage.sol +++ b/test/libsolidity/semanticTests/abiencodedecode/abi_decode_simple_storage.sol @@ -12,5 +12,5 @@ contract C { // ---- // f(bytes): 0x20, 0x80, 0x21, 0x40, 0x7, "abcdefg" -> 0x21, 0x40, 0x7, "abcdefg" // gas irOptimized: 135918 -// gas legacy: 137190 -// gas legacyOptimized: 136082 +// gas legacy: 137181 +// gas legacyOptimized: 136073 diff --git a/test/libsolidity/semanticTests/array/arrays_complex_from_and_to_storage.sol b/test/libsolidity/semanticTests/array/arrays_complex_from_and_to_storage.sol index 7a2a06a2e..7a6602f9d 100644 --- a/test/libsolidity/semanticTests/array/arrays_complex_from_and_to_storage.sol +++ b/test/libsolidity/semanticTests/array/arrays_complex_from_and_to_storage.sol @@ -14,7 +14,7 @@ contract Test { // compileViaYul: also // ---- // set(uint24[3][]): 0x20, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12 -> 0x06 -// gas irOptimized: 189871 +// gas irOptimized: 189817 // gas legacy: 211149 // gas legacyOptimized: 206054 // data(uint256,uint256): 0x02, 0x02 -> 0x09 diff --git a/test/libsolidity/semanticTests/array/byte_array_storage_layout.sol b/test/libsolidity/semanticTests/array/byte_array_storage_layout.sol index 2c238a54b..b176c7e86 100644 --- a/test/libsolidity/semanticTests/array/byte_array_storage_layout.sol +++ b/test/libsolidity/semanticTests/array/byte_array_storage_layout.sol @@ -48,8 +48,8 @@ contract c { // storageEmpty -> 0 // test_long() -> 67 // gas irOptimized: 89148 -// gas legacy: 103590 -// gas legacyOptimized: 101044 +// gas legacy: 103039 +// gas legacyOptimized: 100493 // storageEmpty -> 0 // test_pop() -> 1780731860627700044960722568376592200742329637303199754547598369979433020 // gas legacy: 61930 diff --git a/test/libsolidity/semanticTests/array/byte_array_transitional_2.sol b/test/libsolidity/semanticTests/array/byte_array_transitional_2.sol index 31879057a..76dce6a18 100644 --- a/test/libsolidity/semanticTests/array/byte_array_transitional_2.sol +++ b/test/libsolidity/semanticTests/array/byte_array_transitional_2.sol @@ -19,6 +19,6 @@ contract c { // compileViaYul: also // ---- // test() -> 0 -// gas irOptimized: 158143 -// gas legacy: 189715 -// gas legacyOptimized: 184472 +// gas irOptimized: 157951 +// gas legacy: 188576 +// gas legacyOptimized: 183333 diff --git a/test/libsolidity/semanticTests/array/bytes_length_member.sol b/test/libsolidity/semanticTests/array/bytes_length_member.sol index aaf990ef6..284c1b709 100644 --- a/test/libsolidity/semanticTests/array/bytes_length_member.sol +++ b/test/libsolidity/semanticTests/array/bytes_length_member.sol @@ -16,6 +16,6 @@ contract c { // getLength() -> 0 // set(): 1, 2 -> true // gas irOptimized: 110439 -// gas legacy: 110726 -// gas legacyOptimized: 110567 +// gas legacy: 110723 +// gas legacyOptimized: 110564 // getLength() -> 68 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_calldata_storage.sol b/test/libsolidity/semanticTests/array/copying/array_copy_calldata_storage.sol index 6c876286b..f80da3500 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_calldata_storage.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_calldata_storage.sol @@ -22,7 +22,7 @@ contract c { // compileViaYul: also // ---- // store(uint256[9],uint8[3][]): 21, 22, 23, 24, 25, 26, 27, 28, 29, 0x140, 4, 1, 2, 3, 11, 12, 13, 21, 22, 23, 31, 32, 33 -> 32 -// gas irOptimized: 650647 +// gas irOptimized: 650608 // gas legacy: 694515 // gas legacyOptimized: 694013 // retrieve() -> 9, 28, 9, 28, 4, 3, 32 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_different_packing.sol b/test/libsolidity/semanticTests/array/copying/array_copy_different_packing.sol index 81607a264..6d84d1ecd 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_different_packing.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_different_packing.sol @@ -21,6 +21,6 @@ contract c { // compileViaYul: also // ---- // test() -> 0x01000000000000000000000000000000000000000000000000, 0x02000000000000000000000000000000000000000000000000, 0x03000000000000000000000000000000000000000000000000, 0x04000000000000000000000000000000000000000000000000, 0x05000000000000000000000000000000000000000000000000 -// gas irOptimized: 212571 -// gas legacy: 221883 -// gas legacyOptimized: 220734 +// gas irOptimized: 212568 +// gas legacy: 221856 +// gas legacyOptimized: 220680 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_including_array.sol b/test/libsolidity/semanticTests/array/copying/array_copy_including_array.sol index 1c030deba..65dfc65ab 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_including_array.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_including_array.sol @@ -37,12 +37,12 @@ contract c { // compileViaYul: also // ---- // test() -> 0x02000202 -// gas irOptimized: 4652058 -// gas legacy: 4578341 -// gas legacyOptimized: 4548354 +// gas irOptimized: 4652050 +// gas legacy: 4578320 +// gas legacyOptimized: 4548312 // storageEmpty -> 1 // clear() -> 0, 0 // gas irOptimized: 4483175 -// gas legacy: 4410769 -// gas legacyOptimized: 4382531 +// gas legacy: 4410748 +// gas legacyOptimized: 4382489 // storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_dyn_dyn.sol b/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_dyn_dyn.sol index b4b392974..6eb0de421 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_dyn_dyn.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_dyn_dyn.sol @@ -17,7 +17,7 @@ contract c { // ---- // setData1(uint256,uint256,uint256): 10, 5, 4 -> // copyStorageStorage() -> -// gas irOptimized: 111406 +// gas irOptimized: 111397 // gas legacy: 109278 // gas legacyOptimized: 109268 // getData2(uint256): 5 -> 10, 4 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_struct.sol b/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_struct.sol index db26b4d47..676736dc1 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_struct.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_struct.sol @@ -19,7 +19,7 @@ contract c { // compileViaYul: also // ---- // test() -> 4, 5 -// gas irOptimized: 238826 +// gas irOptimized: 238799 // gas legacy: 238736 // gas legacyOptimized: 237159 // storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_target_leftover.sol b/test/libsolidity/semanticTests/array/copying/array_copy_target_leftover.sol index 1daa061a5..5325e9cdf 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_target_leftover.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_target_leftover.sol @@ -21,5 +21,5 @@ contract c { // ---- // test() -> 0xffffffff, 0x0000000000000000000000000a00090008000700060005000400030002000100, 0x0000000000000000000000000000000000000000000000000000000000000000 // gas irOptimized: 129167 -// gas legacy: 186406 -// gas legacyOptimized: 166126 +// gas legacy: 186184 +// gas legacyOptimized: 165682 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_target_simple.sol b/test/libsolidity/semanticTests/array/copying/array_copy_target_simple.sol index c87f70244..74cd2dc79 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_target_simple.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_target_simple.sol @@ -23,5 +23,5 @@ contract c { // ---- // test() -> 0x01000000000000000000000000000000000000000000000000, 0x02000000000000000000000000000000000000000000000000, 0x03000000000000000000000000000000000000000000000000, 0x04000000000000000000000000000000000000000000000000, 0x0 // gas irOptimized: 294772 -// gas legacy: 303653 -// gas legacyOptimized: 301999 +// gas legacy: 303626 +// gas legacyOptimized: 301945 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_target_simple_2.sol b/test/libsolidity/semanticTests/array/copying/array_copy_target_simple_2.sol index c39f80275..5bf120994 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_target_simple_2.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_target_simple_2.sol @@ -23,5 +23,5 @@ contract c { // ---- // test() -> 0x01000000000000000000000000000000000000000000000000, 0x02000000000000000000000000000000000000000000000000, 0x03000000000000000000000000000000000000000000000000, 0x04000000000000000000000000000000000000000000000000, 0x00 // gas irOptimized: 273963 -// gas legacy: 276381 -// gas legacyOptimized: 275453 +// gas legacy: 276360 +// gas legacyOptimized: 275411 diff --git a/test/libsolidity/semanticTests/array/copying/array_of_function_external_storage_to_storage_dynamic.sol b/test/libsolidity/semanticTests/array/copying/array_of_function_external_storage_to_storage_dynamic.sol index d872534cd..e13c15cab 100644 --- a/test/libsolidity/semanticTests/array/copying/array_of_function_external_storage_to_storage_dynamic.sol +++ b/test/libsolidity/semanticTests/array/copying/array_of_function_external_storage_to_storage_dynamic.sol @@ -48,6 +48,6 @@ contract C { // ---- // copyExternalStorageArrayOfFunctionType() -> true // gas irOptimized: 104669 -// gas legacy: 108725 -// gas legacyOptimized: 102441 +// gas legacy: 108722 +// gas legacyOptimized: 102438 // copyInternalArrayOfFunctionType() -> true diff --git a/test/libsolidity/semanticTests/array/copying/array_of_function_external_storage_to_storage_dynamic_different_mutability.sol b/test/libsolidity/semanticTests/array/copying/array_of_function_external_storage_to_storage_dynamic_different_mutability.sol index 71399a281..7f746c41a 100644 --- a/test/libsolidity/semanticTests/array/copying/array_of_function_external_storage_to_storage_dynamic_different_mutability.sol +++ b/test/libsolidity/semanticTests/array/copying/array_of_function_external_storage_to_storage_dynamic_different_mutability.sol @@ -51,7 +51,7 @@ contract C { // ---- // copyExternalStorageArraysOfFunctionType() -> true // gas irOptimized: 104342 -// gas legacy: 108462 -// gas legacyOptimized: 102174 +// gas legacy: 108459 +// gas legacyOptimized: 102171 // copyInternalArrayOfFunctionType() -> true // gas legacy: 104178 diff --git a/test/libsolidity/semanticTests/array/copying/array_of_struct_calldata_to_storage.sol b/test/libsolidity/semanticTests/array/copying/array_of_struct_calldata_to_storage.sol index b3d950ffa..e8d28e28b 100644 --- a/test/libsolidity/semanticTests/array/copying/array_of_struct_calldata_to_storage.sol +++ b/test/libsolidity/semanticTests/array/copying/array_of_struct_calldata_to_storage.sol @@ -17,4 +17,4 @@ contract C { // compileViaYul: true // ---- // f((uint128,uint64,uint128)[]): 0x20, 3, 0, 0, 12, 0, 11, 0, 10, 0, 0 -> 10, 11, 12 -// gas irOptimized: 121048 +// gas irOptimized: 121021 diff --git a/test/libsolidity/semanticTests/array/copying/bytes_inside_mappings.sol b/test/libsolidity/semanticTests/array/copying/bytes_inside_mappings.sol index ae2698551..26ad58f4c 100644 --- a/test/libsolidity/semanticTests/array/copying/bytes_inside_mappings.sol +++ b/test/libsolidity/semanticTests/array/copying/bytes_inside_mappings.sol @@ -8,12 +8,12 @@ contract c { // ---- // set(uint256): 1, 2 -> true // gas irOptimized: 110604 -// gas legacy: 111091 -// gas legacyOptimized: 110736 +// gas legacy: 111088 +// gas legacyOptimized: 110733 // set(uint256): 2, 2, 3, 4, 5 -> true // gas irOptimized: 177564 -// gas legacy: 178021 -// gas legacyOptimized: 177666 +// gas legacy: 178018 +// gas legacyOptimized: 177663 // storageEmpty -> 0 // copy(uint256,uint256): 1, 2 -> true // storageEmpty -> 0 diff --git a/test/libsolidity/semanticTests/array/copying/bytes_storage_to_storage.sol b/test/libsolidity/semanticTests/array/copying/bytes_storage_to_storage.sol index 87974f053..9c2e3b28e 100644 --- a/test/libsolidity/semanticTests/array/copying/bytes_storage_to_storage.sol +++ b/test/libsolidity/semanticTests/array/copying/bytes_storage_to_storage.sol @@ -20,24 +20,24 @@ contract c { // f(uint256): 0 -> 0x20, 0x00 // f(uint256): 31 -> 0x20, 0x1f, 0x0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e00 // gas irOptimized: 121741 -// gas legacy: 124364 -// gas legacyOptimized: 119898 +// gas legacy: 123884 +// gas legacyOptimized: 119139 // f(uint256): 32 -> 0x20, 0x20, 1780731860627700044960722568376592200742329637303199754547598369979440671 // gas irOptimized: 130733 -// gas legacy: 135431 -// gas legacyOptimized: 130829 +// gas legacy: 134936 +// gas legacyOptimized: 130046 // f(uint256): 33 -> 0x20, 33, 1780731860627700044960722568376592200742329637303199754547598369979440671, 0x2000000000000000000000000000000000000000000000000000000000000000 // gas irOptimized: 137732 -// gas legacy: 142238 -// gas legacyOptimized: 137518 +// gas legacy: 141728 +// gas legacyOptimized: 136711 // f(uint256): 63 -> 0x20, 0x3f, 1780731860627700044960722568376592200742329637303199754547598369979440671, 14532552714582660066924456880521368950258152170031413196862950297402215316992 // gas irOptimized: 152352 -// gas legacy: 160728 -// gas legacyOptimized: 152168 +// gas legacy: 159768 +// gas legacyOptimized: 150641 // f(uint256): 12 -> 0x20, 0x0c, 0x0102030405060708090a0b0000000000000000000000000000000000000000 // gas legacy: 59345 // gas legacyOptimized: 57279 // f(uint256): 129 -> 0x20, 0x81, 1780731860627700044960722568376592200742329637303199754547598369979440671, 0x202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f, 29063324697304692433803953038474361308315562010425523193971352996434451193439, 0x606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f, -57896044618658097711785492504343953926634992332820282019728792003956564819968 // gas irOptimized: 406089 -// gas legacy: 423017 -// gas legacyOptimized: 406021 +// gas legacy: 421067 +// gas legacyOptimized: 402910 diff --git a/test/libsolidity/semanticTests/array/copying/copy_byte_array_in_struct_to_storage.sol b/test/libsolidity/semanticTests/array/copying/copy_byte_array_in_struct_to_storage.sol index 72a837d1b..d17978bf8 100644 --- a/test/libsolidity/semanticTests/array/copying/copy_byte_array_in_struct_to_storage.sol +++ b/test/libsolidity/semanticTests/array/copying/copy_byte_array_in_struct_to_storage.sol @@ -38,11 +38,11 @@ contract C { // ---- // f() -> 0x40, 0x80, 6, 0x6162636465660000000000000000000000000000000000000000000000000000, 0x49, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738390000000000000000000000000000000000000000000000 // gas irOptimized: 179899 -// gas legacy: 180694 -// gas legacyOptimized: 180088 +// gas legacy: 180676 +// gas legacyOptimized: 180070 // g() -> 0x40, 0xc0, 0x49, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738390000000000000000000000000000000000000000000000, 0x11, 0x3132333435363738393233343536373839000000000000000000000000000000 // gas irOptimized: 107274 -// gas legacy: 107895 -// gas legacyOptimized: 107254 +// gas legacy: 107877 +// gas legacyOptimized: 107236 // h() -> 0x40, 0x60, 0x00, 0x00 // storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/copying/copy_byte_array_to_storage.sol b/test/libsolidity/semanticTests/array/copying/copy_byte_array_to_storage.sol index b73f3dc44..b7b8e4be2 100644 --- a/test/libsolidity/semanticTests/array/copying/copy_byte_array_to_storage.sol +++ b/test/libsolidity/semanticTests/array/copying/copy_byte_array_to_storage.sol @@ -48,6 +48,6 @@ contract C { // compileViaYul: also // ---- // f() -> 0xff -// gas irOptimized: 121145 -// gas legacy: 128035 -// gas legacyOptimized: 123476 +// gas irOptimized: 121125 +// gas legacy: 128005 +// gas legacyOptimized: 123446 diff --git a/test/libsolidity/semanticTests/array/copying/copy_function_internal_storage_array.sol b/test/libsolidity/semanticTests/array/copying/copy_function_internal_storage_array.sol index 7550a9225..64cb8edd1 100644 --- a/test/libsolidity/semanticTests/array/copying/copy_function_internal_storage_array.sol +++ b/test/libsolidity/semanticTests/array/copying/copy_function_internal_storage_array.sol @@ -18,6 +18,6 @@ contract C { // compileViaYul: also // ---- // test() -> 7 -// gas irOptimized: 124041 +// gas irOptimized: 124037 // gas legacy: 205196 // gas legacyOptimized: 204987 diff --git a/test/libsolidity/semanticTests/array/copying/copy_removes_bytes_data.sol b/test/libsolidity/semanticTests/array/copying/copy_removes_bytes_data.sol index 8d8bd4d50..9c435f3e1 100644 --- a/test/libsolidity/semanticTests/array/copying/copy_removes_bytes_data.sol +++ b/test/libsolidity/semanticTests/array/copying/copy_removes_bytes_data.sol @@ -10,8 +10,8 @@ contract c { // ---- // set(): 1, 2, 3, 4, 5 -> true // gas irOptimized: 177390 -// gas legacy: 177656 -// gas legacyOptimized: 177496 +// gas legacy: 177653 +// gas legacyOptimized: 177493 // storageEmpty -> 0 // reset() -> true // storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/copying/copying_bytes_multiassign.sol b/test/libsolidity/semanticTests/array/copying/copying_bytes_multiassign.sol index 7b2af9607..ecf9c838a 100644 --- a/test/libsolidity/semanticTests/array/copying/copying_bytes_multiassign.sol +++ b/test/libsolidity/semanticTests/array/copying/copying_bytes_multiassign.sol @@ -22,8 +22,8 @@ contract sender { // ---- // (): 7 -> // gas irOptimized: 110954 -// gas legacy: 111082 -// gas legacyOptimized: 111027 +// gas legacy: 111073 +// gas legacyOptimized: 111018 // val() -> 0 // forward(bool): true -> true // val() -> 0x80 diff --git a/test/libsolidity/semanticTests/array/copying/memory_dyn_2d_bytes_to_storage.sol b/test/libsolidity/semanticTests/array/copying/memory_dyn_2d_bytes_to_storage.sol index 3d4623b79..24de47c27 100644 --- a/test/libsolidity/semanticTests/array/copying/memory_dyn_2d_bytes_to_storage.sol +++ b/test/libsolidity/semanticTests/array/copying/memory_dyn_2d_bytes_to_storage.sol @@ -21,5 +21,5 @@ contract C { // ---- // f() -> 3 // gas irOptimized: 129916 -// gas legacy: 130307 -// gas legacyOptimized: 129363 +// gas legacy: 130181 +// gas legacyOptimized: 129198 diff --git a/test/libsolidity/semanticTests/array/copying/storage_memory_nested.sol b/test/libsolidity/semanticTests/array/copying/storage_memory_nested.sol index ec58360cd..cbeaefd82 100644 --- a/test/libsolidity/semanticTests/array/copying/storage_memory_nested.sol +++ b/test/libsolidity/semanticTests/array/copying/storage_memory_nested.sol @@ -20,5 +20,5 @@ contract C { // ---- // f() -> 1, 2, 3, 4, 5, 6, 7 // gas irOptimized: 207785 -// gas legacy: 212325 -// gas legacyOptimized: 211486 +// gas legacy: 212313 +// gas legacyOptimized: 211462 diff --git a/test/libsolidity/semanticTests/array/copying/storage_memory_nested_bytes.sol b/test/libsolidity/semanticTests/array/copying/storage_memory_nested_bytes.sol index f94b442f3..35fd24fd8 100644 --- a/test/libsolidity/semanticTests/array/copying/storage_memory_nested_bytes.sol +++ b/test/libsolidity/semanticTests/array/copying/storage_memory_nested_bytes.sol @@ -14,5 +14,5 @@ contract C { // ---- // f() -> 0x20, 0x02, 0x40, 0x80, 3, 0x6162630000000000000000000000000000000000000000000000000000000000, 0x99, 44048183304486788312148433451363384677562265908331949128489393215789685032262, 32241931068525137014058842823026578386641954854143559838526554899205067598957, 49951309422467613961193228765530489307475214998374779756599339590522149884499, 0x54555658595a6162636465666768696a6b6c6d6e6f707172737475767778797a, 0x4142434445464748494a4b4c4d4e4f5051525354555658595a00000000000000 // gas irOptimized: 202840 -// gas legacy: 204459 -// gas legacyOptimized: 203437 +// gas legacy: 204441 +// gas legacyOptimized: 203419 diff --git a/test/libsolidity/semanticTests/array/copying/storage_memory_nested_from_pointer.sol b/test/libsolidity/semanticTests/array/copying/storage_memory_nested_from_pointer.sol index ece6f7969..e595c4816 100644 --- a/test/libsolidity/semanticTests/array/copying/storage_memory_nested_from_pointer.sol +++ b/test/libsolidity/semanticTests/array/copying/storage_memory_nested_from_pointer.sol @@ -21,5 +21,5 @@ contract C { // ---- // f() -> 1, 2, 3, 4, 5, 6, 7 // gas irOptimized: 207785 -// gas legacy: 212330 -// gas legacyOptimized: 211491 +// gas legacy: 212318 +// gas legacyOptimized: 211467 diff --git a/test/libsolidity/semanticTests/array/copying/storage_memory_packed_dyn.sol b/test/libsolidity/semanticTests/array/copying/storage_memory_packed_dyn.sol index abcd72ee1..f212c573a 100644 --- a/test/libsolidity/semanticTests/array/copying/storage_memory_packed_dyn.sol +++ b/test/libsolidity/semanticTests/array/copying/storage_memory_packed_dyn.sol @@ -16,5 +16,5 @@ contract C { // ---- // f() -> 2, 3, 4 // gas irOptimized: 114120 -// gas legacy: 126449 -// gas legacyOptimized: 120902 +// gas legacy: 126350 +// gas legacyOptimized: 120704 diff --git a/test/libsolidity/semanticTests/array/delete/bytes_delete_element.sol b/test/libsolidity/semanticTests/array/delete/bytes_delete_element.sol index 149e8768d..00c8c41f6 100644 --- a/test/libsolidity/semanticTests/array/delete/bytes_delete_element.sol +++ b/test/libsolidity/semanticTests/array/delete/bytes_delete_element.sol @@ -19,5 +19,5 @@ contract c { // ---- // test1() -> true // gas irOptimized: 225894 -// gas legacy: 255577 -// gas legacyOptimized: 248611 +// gas legacy: 254650 +// gas legacyOptimized: 247384 diff --git a/test/libsolidity/semanticTests/array/delete/delete_storage_array_packed.sol b/test/libsolidity/semanticTests/array/delete/delete_storage_array_packed.sol index 82c8d6b6c..8d0f6358e 100644 --- a/test/libsolidity/semanticTests/array/delete/delete_storage_array_packed.sol +++ b/test/libsolidity/semanticTests/array/delete/delete_storage_array_packed.sol @@ -16,4 +16,4 @@ contract C { // compileViaYul: also // ---- // f() -> 0, 0, 0 -// gas irOptimized: 91098 +// gas irOptimized: 90992 diff --git a/test/libsolidity/semanticTests/array/dynamic_array_cleanup.sol b/test/libsolidity/semanticTests/array/dynamic_array_cleanup.sol index 019a3fca0..a9eff11f4 100644 --- a/test/libsolidity/semanticTests/array/dynamic_array_cleanup.sol +++ b/test/libsolidity/semanticTests/array/dynamic_array_cleanup.sol @@ -17,8 +17,8 @@ contract c { // storageEmpty -> 1 // fill() -> // gas irOptimized: 519886 -// gas legacy: 521773 -// gas legacyOptimized: 517048 +// gas legacy: 521710 +// gas legacyOptimized: 516922 // storageEmpty -> 0 // halfClear() -> // storageEmpty -> 0 diff --git a/test/libsolidity/semanticTests/array/fixed_array_cleanup.sol b/test/libsolidity/semanticTests/array/fixed_array_cleanup.sol index b09cb5812..c2a2a7b46 100644 --- a/test/libsolidity/semanticTests/array/fixed_array_cleanup.sol +++ b/test/libsolidity/semanticTests/array/fixed_array_cleanup.sol @@ -14,8 +14,8 @@ contract c { // storageEmpty -> 1 // fill() -> // gas irOptimized: 465544 -// gas legacy: 471460 -// gas legacyOptimized: 467520 +// gas legacy: 471400 +// gas legacyOptimized: 467400 // storageEmpty -> 0 // clear() -> // storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/fixed_arrays_as_return_type.sol b/test/libsolidity/semanticTests/array/fixed_arrays_as_return_type.sol index fcf41823e..3b93c930a 100644 --- a/test/libsolidity/semanticTests/array/fixed_arrays_as_return_type.sol +++ b/test/libsolidity/semanticTests/array/fixed_arrays_as_return_type.sol @@ -21,6 +21,6 @@ contract B { // compileViaYul: also // ---- // f() -> 2, 3, 4, 5, 6, 1000, 1001, 1002, 1003, 1004 -// gas irOptimized: 130152 -// gas legacy: 234943 -// gas legacyOptimized: 132863 +// gas irOptimized: 129910 +// gas legacy: 234719 +// gas legacyOptimized: 132639 diff --git a/test/libsolidity/semanticTests/array/fixed_arrays_in_constructors.sol b/test/libsolidity/semanticTests/array/fixed_arrays_in_constructors.sol index 07a054514..0521c45de 100644 --- a/test/libsolidity/semanticTests/array/fixed_arrays_in_constructors.sol +++ b/test/libsolidity/semanticTests/array/fixed_arrays_in_constructors.sol @@ -11,7 +11,7 @@ contract Creator { // compileViaYul: also // ---- // constructor(): 1, 2, 3, 4 -> -// gas irOptimized: 129908 +// gas irOptimized: 128995 // gas legacy: 176789 // gas legacyOptimized: 129585 // r() -> 4 diff --git a/test/libsolidity/semanticTests/array/function_array_cross_calls.sol b/test/libsolidity/semanticTests/array/function_array_cross_calls.sol index 73f9799d4..050595439 100644 --- a/test/libsolidity/semanticTests/array/function_array_cross_calls.sol +++ b/test/libsolidity/semanticTests/array/function_array_cross_calls.sol @@ -45,6 +45,6 @@ contract C { // compileViaYul: also // ---- // test() -> 5, 6, 7 -// gas irOptimized: 298983 -// gas legacy: 452172 -// gas legacyOptimized: 285017 +// gas irOptimized: 298735 +// gas legacy: 452136 +// gas legacyOptimized: 284945 diff --git a/test/libsolidity/semanticTests/array/pop/array_pop_array_transition.sol b/test/libsolidity/semanticTests/array/pop/array_pop_array_transition.sol index f2a98f993..3b6fa4b5b 100644 --- a/test/libsolidity/semanticTests/array/pop/array_pop_array_transition.sol +++ b/test/libsolidity/semanticTests/array/pop/array_pop_array_transition.sol @@ -25,7 +25,7 @@ contract c { // compileViaYul: also // ---- // test() -> 1, 2, 3 -// gas irOptimized: 2271482 -// gas legacy: 2273722 -// gas legacyOptimized: 2262396 +// gas irOptimized: 2271050 +// gas legacy: 2273434 +// gas legacyOptimized: 2261820 // storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/pop/array_pop_uint16_transition.sol b/test/libsolidity/semanticTests/array/pop/array_pop_uint16_transition.sol index 4be29a15d..6ec59a75e 100644 --- a/test/libsolidity/semanticTests/array/pop/array_pop_uint16_transition.sol +++ b/test/libsolidity/semanticTests/array/pop/array_pop_uint16_transition.sol @@ -21,6 +21,6 @@ contract c { // ---- // test() -> 38, 28, 18 // gas irOptimized: 188649 -// gas legacy: 189780 -// gas legacyOptimized: 178870 +// gas legacy: 189492 +// gas legacyOptimized: 178294 // storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/pop/array_pop_uint24_transition.sol b/test/libsolidity/semanticTests/array/pop/array_pop_uint24_transition.sol index 08a403174..de4b2fa1c 100644 --- a/test/libsolidity/semanticTests/array/pop/array_pop_uint24_transition.sol +++ b/test/libsolidity/semanticTests/array/pop/array_pop_uint24_transition.sol @@ -21,6 +21,6 @@ contract c { // ---- // test() -> 20, 10 // gas irOptimized: 159175 -// gas legacy: 159459 -// gas legacyOptimized: 153281 +// gas legacy: 159279 +// gas legacyOptimized: 152921 // storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/pop/byte_array_pop_copy_long.sol b/test/libsolidity/semanticTests/array/pop/byte_array_pop_copy_long.sol index 387d21872..c9f81f37a 100644 --- a/test/libsolidity/semanticTests/array/pop/byte_array_pop_copy_long.sol +++ b/test/libsolidity/semanticTests/array/pop/byte_array_pop_copy_long.sol @@ -13,5 +13,5 @@ contract c { // ---- // test() -> 0x20, 29, 0x0303030303030303030303030303030303030303030303030303030303000000 // gas irOptimized: 109503 -// gas legacy: 127309 -// gas legacyOptimized: 124136 +// gas legacy: 126728 +// gas legacyOptimized: 123444 diff --git a/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty.sol b/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty.sol index c911b1b7c..2b63293cb 100644 --- a/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty.sol +++ b/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty.sol @@ -19,6 +19,6 @@ contract c { // ---- // test() -> true // gas irOptimized: 196545 -// gas legacy: 229864 -// gas legacyOptimized: 210964 +// gas legacy: 228685 +// gas legacyOptimized: 209662 // storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty_garbage_ref.sol b/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty_garbage_ref.sol index 38c0c84d6..1550df0d4 100644 --- a/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty_garbage_ref.sol +++ b/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty_garbage_ref.sol @@ -18,6 +18,6 @@ contract c { // ---- // test() -> // gas irOptimized: 142640 -// gas legacy: 165363 -// gas legacyOptimized: 159446 +// gas legacy: 164430 +// gas legacyOptimized: 157898 // storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/pop/byte_array_pop_masking_long.sol b/test/libsolidity/semanticTests/array/pop/byte_array_pop_masking_long.sol index 6d314fb27..f6f9c10e8 100644 --- a/test/libsolidity/semanticTests/array/pop/byte_array_pop_masking_long.sol +++ b/test/libsolidity/semanticTests/array/pop/byte_array_pop_masking_long.sol @@ -13,5 +13,5 @@ contract c { // ---- // test() -> 0x20, 33, 0x303030303030303030303030303030303030303030303030303030303030303, 0x0300000000000000000000000000000000000000000000000000000000000000 // gas irOptimized: 108493 -// gas legacy: 126187 -// gas legacyOptimized: 123261 +// gas legacy: 125610 +// gas legacyOptimized: 122582 diff --git a/test/libsolidity/semanticTests/array/push/array_push_nested_from_calldata.sol b/test/libsolidity/semanticTests/array/push/array_push_nested_from_calldata.sol index a4be5ad90..55a7d1bfe 100644 --- a/test/libsolidity/semanticTests/array/push/array_push_nested_from_calldata.sol +++ b/test/libsolidity/semanticTests/array/push/array_push_nested_from_calldata.sol @@ -14,6 +14,6 @@ contract C { // compileViaYul: also // ---- // f(uint120[]): 0x20, 3, 1, 2, 3 -> 1 -// gas irOptimized: 113267 +// gas irOptimized: 113258 // gas legacy: 113686 // gas legacyOptimized: 113499 diff --git a/test/libsolidity/semanticTests/array/push/array_push_struct_from_calldata.sol b/test/libsolidity/semanticTests/array/push/array_push_struct_from_calldata.sol index 7546a664b..299aa79c7 100644 --- a/test/libsolidity/semanticTests/array/push/array_push_struct_from_calldata.sol +++ b/test/libsolidity/semanticTests/array/push/array_push_struct_from_calldata.sol @@ -18,6 +18,6 @@ contract c { // compileViaYul: also // ---- // test((uint16,uint16,uint16[3],uint16[])): 0x20, 2, 3, 0, 0, 4, 0xC0, 4, 0, 0, 5, 0, 0 -> 2, 3, 4, 5 -// gas irOptimized: 138732 +// gas irOptimized: 138705 // gas legacy: 145150 // gas legacyOptimized: 139171 diff --git a/test/libsolidity/semanticTests/array/push/byte_array_push_transition.sol b/test/libsolidity/semanticTests/array/push/byte_array_push_transition.sol index 78c817d44..4b8113c1b 100644 --- a/test/libsolidity/semanticTests/array/push/byte_array_push_transition.sol +++ b/test/libsolidity/semanticTests/array/push/byte_array_push_transition.sol @@ -17,6 +17,6 @@ contract c { // compileViaYul: also // ---- // test() -> 0 -// gas irOptimized: 176848 -// gas legacy: 218028 -// gas legacyOptimized: 205124 +// gas irOptimized: 176497 +// gas legacy: 216790 +// gas legacyOptimized: 203886 diff --git a/test/libsolidity/semanticTests/array/push/nested_bytes_push.sol b/test/libsolidity/semanticTests/array/push/nested_bytes_push.sol index 262ba724a..7c4bdcb9a 100644 --- a/test/libsolidity/semanticTests/array/push/nested_bytes_push.sol +++ b/test/libsolidity/semanticTests/array/push/nested_bytes_push.sol @@ -16,5 +16,5 @@ contract C { // ---- // f() -> // gas irOptimized: 179590 -// gas legacy: 180620 -// gas legacyOptimized: 180403 +// gas legacy: 180602 +// gas legacyOptimized: 180385 diff --git a/test/libsolidity/semanticTests/array/push/push_no_args_2d.sol b/test/libsolidity/semanticTests/array/push/push_no_args_2d.sol index 761bf3ee3..610639388 100644 --- a/test/libsolidity/semanticTests/array/push/push_no_args_2d.sol +++ b/test/libsolidity/semanticTests/array/push/push_no_args_2d.sol @@ -30,14 +30,14 @@ contract C { // l() -> 0 // f(uint256,uint256): 42, 64 -> // gas irOptimized: 112528 -// gas legacy: 108234 -// gas legacyOptimized: 102245 +// gas legacy: 108105 +// gas legacyOptimized: 101987 // l() -> 1 // ll(uint256): 0 -> 43 // a(uint256,uint256): 0, 42 -> 64 // f(uint256,uint256): 84, 128 -> // gas irOptimized: 116400 -// gas legacy: 107780 +// gas legacy: 107525 // gas legacyOptimized: 96331 // l() -> 2 // ll(uint256): 1 -> 85 diff --git a/test/libsolidity/semanticTests/array/push/push_no_args_bytes.sol b/test/libsolidity/semanticTests/array/push/push_no_args_bytes.sol index 830f25b02..6c7ae703b 100644 --- a/test/libsolidity/semanticTests/array/push/push_no_args_bytes.sol +++ b/test/libsolidity/semanticTests/array/push/push_no_args_bytes.sol @@ -24,8 +24,8 @@ contract C { // l() -> 0 // g(uint256): 70 -> // gas irOptimized: 185936 -// gas legacy: 184991 -// gas legacyOptimized: 180608 +// gas legacy: 183811 +// gas legacyOptimized: 179218 // l() -> 70 // a(uint256): 69 -> left(69) // f() -> diff --git a/test/libsolidity/semanticTests/array/reusing_memory.sol b/test/libsolidity/semanticTests/array/reusing_memory.sol index 7a05b5328..d783be0b2 100644 --- a/test/libsolidity/semanticTests/array/reusing_memory.sol +++ b/test/libsolidity/semanticTests/array/reusing_memory.sol @@ -26,6 +26,6 @@ contract Main { // compileViaYul: also // ---- // f(uint256): 0x34 -> 0x46bddb1178e94d7f2892ff5f366840eb658911794f2c3a44c450aa2c505186c1 -// gas irOptimized: 113613 +// gas irOptimized: 113604 // gas legacy: 126596 // gas legacyOptimized: 113823 diff --git a/test/libsolidity/semanticTests/calldata/copy_from_calldata_removes_bytes_data.sol b/test/libsolidity/semanticTests/calldata/copy_from_calldata_removes_bytes_data.sol index 7773c6832..4c993d2d2 100644 --- a/test/libsolidity/semanticTests/calldata/copy_from_calldata_removes_bytes_data.sol +++ b/test/libsolidity/semanticTests/calldata/copy_from_calldata_removes_bytes_data.sol @@ -11,9 +11,9 @@ contract c { // compileViaYul: also // ---- // (): 1, 2, 3, 4, 5 -> -// gas irOptimized: 155181 -// gas legacy: 155254 -// gas legacyOptimized: 155217 +// gas irOptimized: 155170 +// gas legacy: 155251 +// gas legacyOptimized: 155214 // checkIfDataIsEmpty() -> false // sendMessage() -> true, 0x40, 0 // checkIfDataIsEmpty() -> true diff --git a/test/libsolidity/semanticTests/constructor/arrays_in_constructors.sol b/test/libsolidity/semanticTests/constructor/arrays_in_constructors.sol index 031deb64c..9f9e96283 100644 --- a/test/libsolidity/semanticTests/constructor/arrays_in_constructors.sol +++ b/test/libsolidity/semanticTests/constructor/arrays_in_constructors.sol @@ -26,6 +26,6 @@ contract Creator { // compileViaYul: also // ---- // f(uint256,address[]): 7, 0x40, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 -> 7, 8 -// gas irOptimized: 443989 +// gas irOptimized: 443720 // gas legacy: 590683 // gas legacyOptimized: 448326 diff --git a/test/libsolidity/semanticTests/constructor/bytes_in_constructors_packer.sol b/test/libsolidity/semanticTests/constructor/bytes_in_constructors_packer.sol index 8264a93ed..a05376298 100644 --- a/test/libsolidity/semanticTests/constructor/bytes_in_constructors_packer.sol +++ b/test/libsolidity/semanticTests/constructor/bytes_in_constructors_packer.sol @@ -26,6 +26,6 @@ contract Creator { // compileViaYul: also // ---- // f(uint256,bytes): 7, 0x40, 78, "abcdefghijklmnopqrstuvwxyzabcdef", "ghijklmnopqrstuvwxyzabcdefghijkl", "mnopqrstuvwxyz" -> 7, "h" -// gas irOptimized: 300837 -// gas legacy: 428917 -// gas legacyOptimized: 298128 +// gas irOptimized: 300834 +// gas legacy: 428711 +// gas legacyOptimized: 297922 diff --git a/test/libsolidity/semanticTests/constructor/bytes_in_constructors_unpacker.sol b/test/libsolidity/semanticTests/constructor/bytes_in_constructors_unpacker.sol index 1a93f53b3..70a636c29 100644 --- a/test/libsolidity/semanticTests/constructor/bytes_in_constructors_unpacker.sol +++ b/test/libsolidity/semanticTests/constructor/bytes_in_constructors_unpacker.sol @@ -11,7 +11,7 @@ contract Test { // ---- // constructor(): 7, 0x40, 78, "abcdefghijklmnopqrstuvwxyzabcdef", "ghijklmnopqrstuvwxyzabcdefghijkl", "mnopqrstuvwxyz" -> // gas irOptimized: 291443 -// gas legacy: 309842 -// gas legacyOptimized: 260801 +// gas legacy: 309607 +// gas legacyOptimized: 260566 // m_x() -> 7 // m_s() -> 0x20, 78, "abcdefghijklmnopqrstuvwxyzabcdef", "ghijklmnopqrstuvwxyzabcdefghijkl", "mnopqrstuvwxyz" diff --git a/test/libsolidity/semanticTests/constructor/constructor_arguments_external.sol b/test/libsolidity/semanticTests/constructor/constructor_arguments_external.sol index 2206fd351..1fa468869 100644 --- a/test/libsolidity/semanticTests/constructor/constructor_arguments_external.sol +++ b/test/libsolidity/semanticTests/constructor/constructor_arguments_external.sol @@ -19,7 +19,7 @@ contract Main { // compileViaYul: also // ---- // constructor(): "abc", true -// gas irOptimized: 107175 +// gas irOptimized: 106221 // gas legacy: 145838 // gas legacyOptimized: 104017 // getFlag() -> true diff --git a/test/libsolidity/semanticTests/constructor/constructor_static_array_argument.sol b/test/libsolidity/semanticTests/constructor/constructor_static_array_argument.sol index f6fab1092..4d3c98dbe 100644 --- a/test/libsolidity/semanticTests/constructor/constructor_static_array_argument.sol +++ b/test/libsolidity/semanticTests/constructor/constructor_static_array_argument.sol @@ -12,7 +12,7 @@ contract C { // compileViaYul: also // ---- // constructor(): 1, 2, 3, 4 -> -// gas irOptimized: 174905 +// gas irOptimized: 174041 // gas legacy: 221377 // gas legacyOptimized: 177671 // a() -> 1 diff --git a/test/libsolidity/semanticTests/constructor/no_callvalue_check.sol b/test/libsolidity/semanticTests/constructor/no_callvalue_check.sol index 3fdbb0785..e50901945 100644 --- a/test/libsolidity/semanticTests/constructor/no_callvalue_check.sol +++ b/test/libsolidity/semanticTests/constructor/no_callvalue_check.sol @@ -19,6 +19,6 @@ contract C { // compileViaYul: also // ---- // f(), 2000 ether -> true -// gas irOptimized: 123037 +// gas irOptimized: 120036 // gas legacy: 123226 // gas legacyOptimized: 123092 diff --git a/test/libsolidity/semanticTests/constructor_inheritance_init_order.sol b/test/libsolidity/semanticTests/constructor_inheritance_init_order.sol index 2518deb92..f17ffe54f 100644 --- a/test/libsolidity/semanticTests/constructor_inheritance_init_order.sol +++ b/test/libsolidity/semanticTests/constructor_inheritance_init_order.sol @@ -15,5 +15,5 @@ contract B is A { // compileViaYul: true // ---- // constructor() -> -// gas irOptimized: 122017 +// gas irOptimized: 121153 // y() -> 42 diff --git a/test/libsolidity/semanticTests/constructor_inheritance_init_order_2.sol b/test/libsolidity/semanticTests/constructor_inheritance_init_order_2.sol index 68506528b..5fafdd045 100644 --- a/test/libsolidity/semanticTests/constructor_inheritance_init_order_2.sol +++ b/test/libsolidity/semanticTests/constructor_inheritance_init_order_2.sol @@ -12,7 +12,7 @@ contract B is A { // compileViaYul: also // ---- // constructor() -> -// gas irOptimized: 122017 +// gas irOptimized: 121153 // gas legacy: 135046 // gas legacyOptimized: 116176 // y() -> 42 diff --git a/test/libsolidity/semanticTests/constructor_with_params.sol b/test/libsolidity/semanticTests/constructor_with_params.sol index cb6192774..21738240a 100644 --- a/test/libsolidity/semanticTests/constructor_with_params.sol +++ b/test/libsolidity/semanticTests/constructor_with_params.sol @@ -11,7 +11,7 @@ contract C { // compileViaYul: also // ---- // constructor(): 2, 0 -> -// gas irOptimized: 104227 +// gas irOptimized: 103290 // gas legacy: 117158 // i() -> 2 // k() -> 0 diff --git a/test/libsolidity/semanticTests/constructor_with_params_diamond_inheritance.sol b/test/libsolidity/semanticTests/constructor_with_params_diamond_inheritance.sol index 8f891116e..635a60c01 100644 --- a/test/libsolidity/semanticTests/constructor_with_params_diamond_inheritance.sol +++ b/test/libsolidity/semanticTests/constructor_with_params_diamond_inheritance.sol @@ -23,7 +23,7 @@ contract D is B, C { // compileViaYul: also // ---- // constructor(): 2, 0 -> -// gas irOptimized: 160166 +// gas irOptimized: 160093 // gas legacy: 170665 // gas legacyOptimized: 145396 // i() -> 2 diff --git a/test/libsolidity/semanticTests/constructor_with_params_inheritance.sol b/test/libsolidity/semanticTests/constructor_with_params_inheritance.sol index 3d90783f8..2d8b667ef 100644 --- a/test/libsolidity/semanticTests/constructor_with_params_inheritance.sol +++ b/test/libsolidity/semanticTests/constructor_with_params_inheritance.sol @@ -14,7 +14,7 @@ contract D is C { // compileViaYul: also // ---- // constructor(): 2, 0 -> -// gas irOptimized: 124844 +// gas irOptimized: 123907 // gas legacy: 139250 // gas legacyOptimized: 119367 // i() -> 2 diff --git a/test/libsolidity/semanticTests/events/event_emit_from_other_contract.sol b/test/libsolidity/semanticTests/events/event_emit_from_other_contract.sol index 5ec47a4a9..19c05a156 100644 --- a/test/libsolidity/semanticTests/events/event_emit_from_other_contract.sol +++ b/test/libsolidity/semanticTests/events/event_emit_from_other_contract.sol @@ -17,7 +17,7 @@ contract C { // compileViaYul: also // ---- // constructor() -> -// gas irOptimized: 173672 +// gas irOptimized: 172802 // gas legacy: 250376 // gas legacyOptimized: 174522 // deposit(bytes32), 18 wei: 0x1234 -> diff --git a/test/libsolidity/semanticTests/events/event_indexed_string.sol b/test/libsolidity/semanticTests/events/event_indexed_string.sol index d35db93c4..5d3ad5840 100644 --- a/test/libsolidity/semanticTests/events/event_indexed_string.sol +++ b/test/libsolidity/semanticTests/events/event_indexed_string.sol @@ -20,5 +20,5 @@ contract C { // deposit() -> // ~ emit E(string,uint256[4]): #0xa7fb06bb999a5eb9aff9e0779953f4e1e4ce58044936c2f51c7fb879b85c08bd, #0xe755d8cc1a8cde16a2a31160dcd8017ac32d7e2f13215b29a23cdae40a78aa81 // gas irOptimized: 343396 -// gas legacy: 390742 -// gas legacyOptimized: 376774 +// gas legacy: 388679 +// gas legacyOptimized: 374441 diff --git a/test/libsolidity/semanticTests/externalContracts/FixedFeeRegistrar.sol b/test/libsolidity/semanticTests/externalContracts/FixedFeeRegistrar.sol index e6d6c478b..9965c786e 100644 --- a/test/libsolidity/semanticTests/externalContracts/FixedFeeRegistrar.sol +++ b/test/libsolidity/semanticTests/externalContracts/FixedFeeRegistrar.sol @@ -76,9 +76,9 @@ contract FixedFeeRegistrar is Registrar { // compileViaYul: also // ---- // constructor() -// gas irOptimized: 413485 -// gas legacy: 936897 -// gas legacyOptimized: 490983 +// gas irOptimized: 413269 +// gas legacy: 935817 +// gas legacyOptimized: 489951 // reserve(string), 69 ether: 0x20, 3, "abc" -> // ~ emit Changed(string): #0x4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45 // gas irOptimized: 45967 diff --git a/test/libsolidity/semanticTests/externalContracts/base64.sol b/test/libsolidity/semanticTests/externalContracts/base64.sol index fd17c5d78..02c858763 100644 --- a/test/libsolidity/semanticTests/externalContracts/base64.sol +++ b/test/libsolidity/semanticTests/externalContracts/base64.sol @@ -35,8 +35,8 @@ contract test { // ---- // constructor() // gas irOptimized: 450044 -// gas legacy: 766936 -// gas legacyOptimized: 543094 +// gas legacy: 765640 +// gas legacyOptimized: 541810 // encode_inline_asm(bytes): 0x20, 0 -> 0x20, 0 // encode_inline_asm(bytes): 0x20, 1, "f" -> 0x20, 4, "Zg==" // encode_inline_asm(bytes): 0x20, 2, "fo" -> 0x20, 4, "Zm8=" @@ -53,9 +53,9 @@ contract test { // encode_no_asm(bytes): 0x20, 6, "foobar" -> 0x20, 8, "Zm9vYmFy" // encode_inline_asm_large() // gas irOptimized: 1385047 -// gas legacy: 1658033 -// gas legacyOptimized: 1210033 +// gas legacy: 1652033 +// gas legacyOptimized: 1201033 // encode_no_asm_large() // gas irOptimized: 3335101 -// gas legacy: 4801077 -// gas legacyOptimized: 2929077 +// gas legacy: 4777077 +// gas legacyOptimized: 2890077 diff --git a/test/libsolidity/semanticTests/externalContracts/deposit_contract.sol b/test/libsolidity/semanticTests/externalContracts/deposit_contract.sol index d98e73792..42a9207fd 100644 --- a/test/libsolidity/semanticTests/externalContracts/deposit_contract.sol +++ b/test/libsolidity/semanticTests/externalContracts/deposit_contract.sol @@ -178,35 +178,35 @@ contract DepositContract is IDepositContract, ERC165 { // compileViaYul: also // ---- // constructor() -// gas irOptimized: 1543359 -// gas legacy: 2436584 -// gas legacyOptimized: 1776483 +// gas irOptimized: 1542927 +// gas legacy: 2435803 +// gas legacyOptimized: 1775425 // supportsInterface(bytes4): 0x0 -> 0 // supportsInterface(bytes4): 0xffffffff00000000000000000000000000000000000000000000000000000000 -> false # defined to be false by ERC-165 # // supportsInterface(bytes4): 0x01ffc9a700000000000000000000000000000000000000000000000000000000 -> true # ERC-165 id # // supportsInterface(bytes4): 0x8564090700000000000000000000000000000000000000000000000000000000 -> true # the deposit interface id # // get_deposit_root() -> 0xd70a234731285c6804c2a4f56711ddb8c82c99740f207854891028af34e27e5e // gas irOptimized: 122135 -// gas legacy: 150465 -// gas legacyOptimized: 122798 +// gas legacy: 150273 +// gas legacyOptimized: 122510 // get_deposit_count() -> 0x20, 8, 0 # TODO: check balance and logs after each deposit # // deposit(bytes,bytes,bytes,bytes32), 32 ether: 0 -> FAILURE # Empty input # // get_deposit_root() -> 0xd70a234731285c6804c2a4f56711ddb8c82c99740f207854891028af34e27e5e // gas irOptimized: 122135 -// gas legacy: 150465 -// gas legacyOptimized: 122798 +// gas legacy: 150273 +// gas legacyOptimized: 122510 // get_deposit_count() -> 0x20, 8, 0 // deposit(bytes,bytes,bytes,bytes32), 1 ether: 0x80, 0xe0, 0x120, 0xaa4a8d0b7d9077248630f1a4701ae9764e42271d7f22b7838778411857fd349e, 0x30, 0x933ad9491b62059dd065b560d256d8957a8c402cc6e8d8ee7290ae11e8f73292, 0x67a8811c397529dac52ae1342ba58c9500000000000000000000000000000000, 0x20, 0x00f50428677c60f997aadeab24aabf7fceaef491c96a52b463ae91f95611cf71, 0x60, 0xa29d01cc8c6296a8150e515b5995390ef841dc18948aa3e79be6d7c1851b4cbb, 0x5d6ff49fa70b9c782399506a22a85193151b9b691245cebafd2063012443c132, 0x4b6c36debaedefb7b2d71b0503ffdc00150aaffd42e63358238ec888901738b8 -> # txhash: 0x7085c586686d666e8bb6e9477a0f0b09565b2060a11f1c4209d3a52295033832 # // ~ emit DepositEvent(bytes,bytes,bytes,bytes,bytes): 0xa0, 0x0100, 0x0140, 0x0180, 0x0200, 0x30, 0x933ad9491b62059dd065b560d256d8957a8c402cc6e8d8ee7290ae11e8f73292, 0x67a8811c397529dac52ae1342ba58c9500000000000000000000000000000000, 0x20, 0xf50428677c60f997aadeab24aabf7fceaef491c96a52b463ae91f95611cf71, 0x08, 0xca9a3b00000000000000000000000000000000000000000000000000000000, 0x60, 0xa29d01cc8c6296a8150e515b5995390ef841dc18948aa3e79be6d7c1851b4cbb, 0x5d6ff49fa70b9c782399506a22a85193151b9b691245cebafd2063012443c132, 0x4b6c36debaedefb7b2d71b0503ffdc00150aaffd42e63358238ec888901738b8, 0x08, 0x00 // get_deposit_root() -> 0x2089653123d9c721215120b6db6738ba273bbc5228ac093b1f983badcdc8a438 // gas irOptimized: 122114 -// gas legacy: 150475 -// gas legacyOptimized: 122811 +// gas legacy: 150283 +// gas legacyOptimized: 122523 // get_deposit_count() -> 0x20, 8, 0x0100000000000000000000000000000000000000000000000000000000000000 // deposit(bytes,bytes,bytes,bytes32), 32 ether: 0x80, 0xe0, 0x120, 0xdbd986dc85ceb382708cf90a3500f500f0a393c5ece76963ac3ed72eccd2c301, 0x30, 0xb2ce0f79f90e7b3a113ca5783c65756f96c4b4673c2b5c1eb4efc22280259441, 0x06d601211e8866dc5b50dc48a244dd7c00000000000000000000000000000000, 0x20, 0x00344b6c73f71b11c56aba0d01b7d8ad83559f209d0a4101a515f6ad54c89771, 0x60, 0x945caaf82d18e78c033927d51f452ebcd76524497b91d7a11219cb3db6a1d369, 0x7595fc095ce489e46b2ef129591f2f6d079be4faaf345a02c5eb133c072e7c56, 0x0c6c3617eee66b4b878165c502357d49485326bc6b31bc96873f308c8f19c09d -> # txhash: 0x404d8e109822ce448e68f45216c12cb051b784d068fbe98317ab8e50c58304ac # // ~ emit DepositEvent(bytes,bytes,bytes,bytes,bytes): 0xa0, 0x0100, 0x0140, 0x0180, 0x0200, 0x30, 0xb2ce0f79f90e7b3a113ca5783c65756f96c4b4673c2b5c1eb4efc22280259441, 0x06d601211e8866dc5b50dc48a244dd7c00000000000000000000000000000000, 0x20, 0x344b6c73f71b11c56aba0d01b7d8ad83559f209d0a4101a515f6ad54c89771, 0x08, 0x40597307000000000000000000000000000000000000000000000000000000, 0x60, 0x945caaf82d18e78c033927d51f452ebcd76524497b91d7a11219cb3db6a1d369, 0x7595fc095ce489e46b2ef129591f2f6d079be4faaf345a02c5eb133c072e7c56, 0x0c6c3617eee66b4b878165c502357d49485326bc6b31bc96873f308c8f19c09d, 0x08, 0x0100000000000000000000000000000000000000000000000000000000000000 // get_deposit_root() -> 0x40255975859377d912c53aa853245ebd939bdd2b33a28e084babdcc1ed8238ee // gas irOptimized: 122114 -// gas legacy: 150475 -// gas legacyOptimized: 122811 +// gas legacy: 150283 +// gas legacyOptimized: 122523 // get_deposit_count() -> 0x20, 8, 0x0200000000000000000000000000000000000000000000000000000000000000 diff --git a/test/libsolidity/semanticTests/externalContracts/prbmath_signed.sol b/test/libsolidity/semanticTests/externalContracts/prbmath_signed.sol index 56abe4a9d..bcb4238a7 100644 --- a/test/libsolidity/semanticTests/externalContracts/prbmath_signed.sol +++ b/test/libsolidity/semanticTests/externalContracts/prbmath_signed.sol @@ -50,9 +50,9 @@ contract test { // compileViaYul: also // ---- // constructor() -// gas irOptimized: 1938339 -// gas legacy: 2480887 -// gas legacyOptimized: 1874490 +// gas irOptimized: 1937251 +// gas legacy: 2478955 +// gas legacyOptimized: 1877737 // div(int256,int256): 3141592653589793238, 88714123 -> 35412542528203691288251815328 // gas irOptimized: 22137 // gas legacy: 22767 diff --git a/test/libsolidity/semanticTests/externalContracts/prbmath_unsigned.sol b/test/libsolidity/semanticTests/externalContracts/prbmath_unsigned.sol index 0488179f1..46e059885 100644 --- a/test/libsolidity/semanticTests/externalContracts/prbmath_unsigned.sol +++ b/test/libsolidity/semanticTests/externalContracts/prbmath_unsigned.sol @@ -50,9 +50,9 @@ contract test { // compileViaYul: also // ---- // constructor() -// gas irOptimized: 1792108 -// gas legacy: 2250130 -// gas legacyOptimized: 1746528 +// gas irOptimized: 1791688 +// gas legacy: 2248594 +// gas legacyOptimized: 1749096 // div(uint256,uint256): 3141592653589793238, 88714123 -> 35412542528203691288251815328 // gas irOptimized: 22004 // gas legacy: 22497 diff --git a/test/libsolidity/semanticTests/externalContracts/ramanujan_pi.sol b/test/libsolidity/semanticTests/externalContracts/ramanujan_pi.sol index 45976217b..eb1b5d841 100644 --- a/test/libsolidity/semanticTests/externalContracts/ramanujan_pi.sol +++ b/test/libsolidity/semanticTests/externalContracts/ramanujan_pi.sol @@ -35,9 +35,9 @@ contract test { // compileViaYul: also // ---- // constructor() -// gas irOptimized: 465789 -// gas legacy: 672749 -// gas legacyOptimized: 479606 +// gas irOptimized: 464709 +// gas legacy: 671453 +// gas legacyOptimized: 480242 // prb_pi() -> 3141592656369545286 // gas irOptimized: 57478 // gas legacy: 98903 diff --git a/test/libsolidity/semanticTests/externalContracts/snark.sol b/test/libsolidity/semanticTests/externalContracts/snark.sol index 8f6b939fd..05b4ddb25 100644 --- a/test/libsolidity/semanticTests/externalContracts/snark.sol +++ b/test/libsolidity/semanticTests/externalContracts/snark.sol @@ -298,5 +298,5 @@ contract Test { // verifyTx() -> true // ~ emit Verified(string): 0x20, 0x16, "Successfully verified." // gas irOptimized: 95261 -// gas legacy: 114094 +// gas legacy: 113731 // gas legacyOptimized: 83670 diff --git a/test/libsolidity/semanticTests/externalContracts/strings.sol b/test/libsolidity/semanticTests/externalContracts/strings.sol index a16f884e8..9f7084410 100644 --- a/test/libsolidity/semanticTests/externalContracts/strings.sol +++ b/test/libsolidity/semanticTests/externalContracts/strings.sol @@ -51,9 +51,9 @@ contract test { // compileViaYul: also // ---- // constructor() -// gas irOptimized: 707330 -// gas legacy: 1130761 -// gas legacyOptimized: 750416 +// gas irOptimized: 704522 +// gas legacy: 1127730 +// gas legacyOptimized: 753807 // toSlice(string): 0x20, 11, "hello world" -> 11, 0xa0 // gas irOptimized: 22660 // gas legacy: 23190 @@ -71,6 +71,6 @@ contract test { // gas legacy: 31621 // gas legacyOptimized: 27914 // benchmark(string,bytes32): 0x40, 0x0842021, 8, "solidity" -> 0x2020 -// gas irOptimized: 2040045 -// gas legacy: 4381235 -// gas legacyOptimized: 2317529 +// gas irOptimized: 2040024 +// gas legacy: 4356286 +// gas legacyOptimized: 2268278 diff --git a/test/libsolidity/semanticTests/functionCall/creation_function_call_with_args.sol b/test/libsolidity/semanticTests/functionCall/creation_function_call_with_args.sol index 0b9407814..a67b1b5ad 100644 --- a/test/libsolidity/semanticTests/functionCall/creation_function_call_with_args.sol +++ b/test/libsolidity/semanticTests/functionCall/creation_function_call_with_args.sol @@ -17,7 +17,7 @@ contract D { // compileViaYul: also // ---- // constructor(): 2 -> -// gas irOptimized: 203982 +// gas irOptimized: 203909 // gas legacy: 245842 // gas legacyOptimized: 195676 // f() -> 2 diff --git a/test/libsolidity/semanticTests/functionCall/creation_function_call_with_salt.sol b/test/libsolidity/semanticTests/functionCall/creation_function_call_with_salt.sol index a4796ac82..b03734532 100644 --- a/test/libsolidity/semanticTests/functionCall/creation_function_call_with_salt.sol +++ b/test/libsolidity/semanticTests/functionCall/creation_function_call_with_salt.sol @@ -18,7 +18,7 @@ contract D { // compileViaYul: also // ---- // constructor(): 2 -> -// gas irOptimized: 204145 +// gas irOptimized: 204072 // gas legacy: 246202 // gas legacyOptimized: 195914 // f() -> 2 diff --git a/test/libsolidity/semanticTests/functionCall/external_call_to_nonexisting.sol b/test/libsolidity/semanticTests/functionCall/external_call_to_nonexisting.sol index 030aeaa10..b74680c96 100644 --- a/test/libsolidity/semanticTests/functionCall/external_call_to_nonexisting.sol +++ b/test/libsolidity/semanticTests/functionCall/external_call_to_nonexisting.sol @@ -25,9 +25,9 @@ contract C { // compileViaYul: also // ---- // constructor(), 1 ether -> -// gas irOptimized: 315341 -// gas legacy: 465314 -// gas legacyOptimized: 304481 +// gas irOptimized: 314681 +// gas legacy: 464030 +// gas legacyOptimized: 304049 // f(uint256): 0 -> FAILURE // f(uint256): 1 -> FAILURE // f(uint256): 2 -> FAILURE diff --git a/test/libsolidity/semanticTests/functionCall/external_call_to_nonexisting_debugstrings.sol b/test/libsolidity/semanticTests/functionCall/external_call_to_nonexisting_debugstrings.sol index cfbf1bcc1..124f69034 100644 --- a/test/libsolidity/semanticTests/functionCall/external_call_to_nonexisting_debugstrings.sol +++ b/test/libsolidity/semanticTests/functionCall/external_call_to_nonexisting_debugstrings.sol @@ -27,9 +27,9 @@ contract C { // revertStrings: debug // ---- // constructor(), 1 ether -> -// gas irOptimized: 452673 -// gas legacy: 834272 -// gas legacyOptimized: 510004 +// gas irOptimized: 449901 +// gas legacy: 832976 +// gas legacyOptimized: 509560 // f(uint256): 0 -> FAILURE, hex"08c379a0", 0x20, 37, "Target contract does not contain", " code" // f(uint256): 1 -> FAILURE, hex"08c379a0", 0x20, 37, "Target contract does not contain", " code" // f(uint256): 2 -> FAILURE, hex"08c379a0", 0x20, 37, "Target contract does not contain", " code" diff --git a/test/libsolidity/semanticTests/functionCall/failed_create.sol b/test/libsolidity/semanticTests/functionCall/failed_create.sol index 2ebf8740d..933bf342d 100644 --- a/test/libsolidity/semanticTests/functionCall/failed_create.sol +++ b/test/libsolidity/semanticTests/functionCall/failed_create.sol @@ -18,9 +18,9 @@ contract C { // compileViaYul: also // ---- // constructor(), 20 wei -// gas irOptimized: 219285 -// gas legacy: 294569 -// gas legacyOptimized: 174699 +// gas irOptimized: 216903 +// gas legacy: 294335 +// gas legacyOptimized: 174279 // f(uint256): 20 -> 1370859564726510389319704988634906228201275401179 // x() -> 1 // f(uint256): 20 -> FAILURE diff --git a/test/libsolidity/semanticTests/functionCall/gas_and_value_basic.sol b/test/libsolidity/semanticTests/functionCall/gas_and_value_basic.sol index 4321753d6..ac51947c3 100644 --- a/test/libsolidity/semanticTests/functionCall/gas_and_value_basic.sol +++ b/test/libsolidity/semanticTests/functionCall/gas_and_value_basic.sol @@ -41,7 +41,7 @@ contract test { // compileViaYul: also // ---- // constructor(), 20 wei -> -// gas irOptimized: 283040 +// gas irOptimized: 282824 // gas legacy: 402654 // gas legacyOptimized: 274470 // sendAmount(uint256): 5 -> 5 diff --git a/test/libsolidity/semanticTests/functionCall/gas_and_value_brace_syntax.sol b/test/libsolidity/semanticTests/functionCall/gas_and_value_brace_syntax.sol index 2f89517b7..0eb9648be 100644 --- a/test/libsolidity/semanticTests/functionCall/gas_and_value_brace_syntax.sol +++ b/test/libsolidity/semanticTests/functionCall/gas_and_value_brace_syntax.sol @@ -40,7 +40,7 @@ contract test { // compileViaYul: also // ---- // constructor(), 20 wei -> -// gas irOptimized: 283040 +// gas irOptimized: 282824 // gas legacy: 402654 // gas legacyOptimized: 274470 // sendAmount(uint256): 5 -> 5 diff --git a/test/libsolidity/semanticTests/functionCall/mapping_array_internal_argument.sol b/test/libsolidity/semanticTests/functionCall/mapping_array_internal_argument.sol index f1e2f1116..92b75ba4e 100644 --- a/test/libsolidity/semanticTests/functionCall/mapping_array_internal_argument.sol +++ b/test/libsolidity/semanticTests/functionCall/mapping_array_internal_argument.sol @@ -20,7 +20,7 @@ contract test { // compileViaYul: also // ---- // set(uint8,uint8,uint8,uint8,uint8): 1, 21, 22, 42, 43 -> 0, 0, 0, 0 -// gas irOptimized: 111929 +// gas irOptimized: 111914 // gas legacy: 113806 // gas legacyOptimized: 111781 // get(uint8): 1 -> 21, 22, 42, 43 diff --git a/test/libsolidity/semanticTests/functionCall/send_zero_ether.sol b/test/libsolidity/semanticTests/functionCall/send_zero_ether.sol index 617a6dec2..1524c46d0 100644 --- a/test/libsolidity/semanticTests/functionCall/send_zero_ether.sol +++ b/test/libsolidity/semanticTests/functionCall/send_zero_ether.sol @@ -19,7 +19,7 @@ contract Main { // compileViaYul: also // ---- // constructor(), 20 wei -> -// gas irOptimized: 102862 +// gas irOptimized: 101782 // gas legacy: 116691 // gas legacyOptimized: 100361 // s() -> true diff --git a/test/libsolidity/semanticTests/inheritance/value_for_constructor.sol b/test/libsolidity/semanticTests/inheritance/value_for_constructor.sol index aea318e65..354e5d82b 100644 --- a/test/libsolidity/semanticTests/inheritance/value_for_constructor.sol +++ b/test/libsolidity/semanticTests/inheritance/value_for_constructor.sol @@ -42,7 +42,7 @@ contract Main { // compileViaYul: also // ---- // constructor(), 22 wei -> -// gas irOptimized: 284321 +// gas irOptimized: 282916 // gas legacy: 402045 // gas legacyOptimized: 266772 // getFlag() -> true diff --git a/test/libsolidity/semanticTests/isoltestTesting/balance_other_contract.sol b/test/libsolidity/semanticTests/isoltestTesting/balance_other_contract.sol index 8d37ed809..94128fbc4 100644 --- a/test/libsolidity/semanticTests/isoltestTesting/balance_other_contract.sol +++ b/test/libsolidity/semanticTests/isoltestTesting/balance_other_contract.sol @@ -18,7 +18,7 @@ contract ClientReceipt { // compileViaYul: also // ---- // constructor(), 2000 wei -> -// gas irOptimized: 188162 +// gas irOptimized: 187946 // gas legacy: 235195 // gas legacyOptimized: 176766 // balance -> 1500 diff --git a/test/libsolidity/semanticTests/libraries/internal_types_in_library.sol b/test/libsolidity/semanticTests/libraries/internal_types_in_library.sol index ac61fad71..9cf5f65ff 100644 --- a/test/libsolidity/semanticTests/libraries/internal_types_in_library.sol +++ b/test/libsolidity/semanticTests/libraries/internal_types_in_library.sol @@ -25,6 +25,6 @@ contract Test { // ---- // library: Lib // f() -> 4, 0x11 -// gas irOptimized: 115874 -// gas legacy: 135952 -// gas legacyOptimized: 119643 +// gas irOptimized: 115868 +// gas legacy: 135820 +// gas legacyOptimized: 119448 diff --git a/test/libsolidity/semanticTests/libraries/using_library_mappings_public.sol b/test/libsolidity/semanticTests/libraries/using_library_mappings_public.sol index e8d22c279..60741d4c4 100644 --- a/test/libsolidity/semanticTests/libraries/using_library_mappings_public.sol +++ b/test/libsolidity/semanticTests/libraries/using_library_mappings_public.sol @@ -22,6 +22,6 @@ contract Test { // ---- // library: Lib // f() -> 1, 0, 0x2a, 0x17, 0, 0x63 -// gas irOptimized: 119561 +// gas irOptimized: 119501 // gas legacy: 124793 // gas legacyOptimized: 119694 diff --git a/test/libsolidity/semanticTests/salted_create/salted_create.sol b/test/libsolidity/semanticTests/salted_create/salted_create.sol index 5374d2352..51b987c2c 100644 --- a/test/libsolidity/semanticTests/salted_create/salted_create.sol +++ b/test/libsolidity/semanticTests/salted_create/salted_create.sol @@ -22,6 +22,6 @@ contract A { // ---- // different_salt() -> true // same_salt() -> true -// gas irOptimized: 98438914 +// gas irOptimized: 98438898 // gas legacy: 98439116 // gas legacyOptimized: 98438970 diff --git a/test/libsolidity/semanticTests/salted_create/salted_create_with_value.sol b/test/libsolidity/semanticTests/salted_create/salted_create_with_value.sol index 780cc32b8..aab46a9a4 100644 --- a/test/libsolidity/semanticTests/salted_create/salted_create_with_value.sol +++ b/test/libsolidity/semanticTests/salted_create/salted_create_with_value.sol @@ -22,6 +22,6 @@ contract A { // compileViaYul: also // ---- // f(), 10 ether -> 3007, 3008, 3009 -// gas irOptimized: 272467 +// gas irOptimized: 272431 // gas legacy: 422501 // gas legacyOptimized: 287472 diff --git a/test/libsolidity/semanticTests/smoke/constructor.sol b/test/libsolidity/semanticTests/smoke/constructor.sol index a6e812e9a..44d7d502f 100644 --- a/test/libsolidity/semanticTests/smoke/constructor.sol +++ b/test/libsolidity/semanticTests/smoke/constructor.sol @@ -14,7 +14,7 @@ contract C { // compileViaYul: also // ---- // constructor(), 2 wei: 3 -> -// gas irOptimized: 111699 +// gas irOptimized: 111607 // gas legacy: 151416 // gas legacyOptimized: 108388 // state() -> 3 diff --git a/test/libsolidity/semanticTests/state/blockhash_basic.sol b/test/libsolidity/semanticTests/state/blockhash_basic.sol index 9abeb90aa..513bf0b8e 100644 --- a/test/libsolidity/semanticTests/state/blockhash_basic.sol +++ b/test/libsolidity/semanticTests/state/blockhash_basic.sol @@ -14,7 +14,7 @@ contract C { // compileViaYul: also // ---- // constructor() -// gas irOptimized: 115297 +// gas irOptimized: 115278 // gas legacy: 155081 // gas legacyOptimized: 107997 // genesisHash() -> 0x3737373737373737373737373737373737373737373737373737373737373737 diff --git a/test/libsolidity/semanticTests/structs/calldata/calldata_struct_with_nested_array_to_storage.sol b/test/libsolidity/semanticTests/structs/calldata/calldata_struct_with_nested_array_to_storage.sol index 6e65cd239..c5c484df7 100644 --- a/test/libsolidity/semanticTests/structs/calldata/calldata_struct_with_nested_array_to_storage.sol +++ b/test/libsolidity/semanticTests/structs/calldata/calldata_struct_with_nested_array_to_storage.sol @@ -18,6 +18,6 @@ contract C { // compileViaYul: also // ---- // f(uint32,(uint128,uint256[][2],uint32)): 55, 0x40, 77, 0x60, 88, 0x40, 0x40, 2, 1, 2 -> 55, 77, 1, 2, 88 -// gas irOptimized: 203312 +// gas irOptimized: 203303 // gas legacy: 209194 // gas legacyOptimized: 203583 diff --git a/test/libsolidity/semanticTests/structs/copy_struct_array_from_storage.sol b/test/libsolidity/semanticTests/structs/copy_struct_array_from_storage.sol index 258ff350b..876a7f6c8 100644 --- a/test/libsolidity/semanticTests/structs/copy_struct_array_from_storage.sol +++ b/test/libsolidity/semanticTests/structs/copy_struct_array_from_storage.sol @@ -88,7 +88,7 @@ contract Test { // compileViaYul: also // ---- // test1() -> true -// gas irOptimized: 150545 +// gas irOptimized: 150533 // gas legacy: 150266 // gas legacyOptimized: 149875 // test2() -> true diff --git a/test/libsolidity/semanticTests/structs/struct_containing_bytes_copy_and_delete.sol b/test/libsolidity/semanticTests/structs/struct_containing_bytes_copy_and_delete.sol index 6b5d1f022..f77156d64 100644 --- a/test/libsolidity/semanticTests/structs/struct_containing_bytes_copy_and_delete.sol +++ b/test/libsolidity/semanticTests/structs/struct_containing_bytes_copy_and_delete.sol @@ -26,8 +26,8 @@ contract c { // storageEmpty -> 1 // set(uint256,bytes,uint256): 12, 0x60, 13, 33, "12345678901234567890123456789012", "3" -> true // gas irOptimized: 133728 -// gas legacy: 134436 -// gas legacyOptimized: 133879 +// gas legacy: 134433 +// gas legacyOptimized: 133876 // test(uint256): 32 -> "3" // storageEmpty -> 0 // copy() -> true diff --git a/test/libsolidity/semanticTests/structs/struct_copy.sol b/test/libsolidity/semanticTests/structs/struct_copy.sol index 03a063bb8..62a8baaed 100644 --- a/test/libsolidity/semanticTests/structs/struct_copy.sol +++ b/test/libsolidity/semanticTests/structs/struct_copy.sol @@ -43,7 +43,7 @@ contract c { // gas legacyOptimized: 110006 // retrieve(uint256): 7 -> 1, 3, 4, 2 // copy(uint256,uint256): 7, 8 -> true -// gas irOptimized: 118597 +// gas irOptimized: 118591 // gas legacy: 119166 // gas legacyOptimized: 118622 // retrieve(uint256): 7 -> 1, 3, 4, 2 diff --git a/test/libsolidity/semanticTests/structs/struct_copy_via_local.sol b/test/libsolidity/semanticTests/structs/struct_copy_via_local.sol index 21757ea40..4305687b7 100644 --- a/test/libsolidity/semanticTests/structs/struct_copy_via_local.sol +++ b/test/libsolidity/semanticTests/structs/struct_copy_via_local.sol @@ -21,6 +21,6 @@ contract c { // compileViaYul: also // ---- // test() -> true -// gas irOptimized: 110186 +// gas irOptimized: 110177 // gas legacy: 110627 // gas legacyOptimized: 109706 diff --git a/test/libsolidity/semanticTests/structs/struct_delete_storage_with_arrays_small.sol b/test/libsolidity/semanticTests/structs/struct_delete_storage_with_arrays_small.sol index 6f88df394..abc10d8aa 100644 --- a/test/libsolidity/semanticTests/structs/struct_delete_storage_with_arrays_small.sol +++ b/test/libsolidity/semanticTests/structs/struct_delete_storage_with_arrays_small.sol @@ -27,4 +27,4 @@ contract C { // compileViaYul: true // ---- // f() -> 0 -// gas irOptimized: 111896 +// gas irOptimized: 112129 diff --git a/test/libsolidity/semanticTests/structs/struct_memory_to_storage_function_ptr.sol b/test/libsolidity/semanticTests/structs/struct_memory_to_storage_function_ptr.sol index fe791a68d..936039f5e 100644 --- a/test/libsolidity/semanticTests/structs/struct_memory_to_storage_function_ptr.sol +++ b/test/libsolidity/semanticTests/structs/struct_memory_to_storage_function_ptr.sol @@ -32,6 +32,6 @@ contract C { // compileViaYul: also // ---- // f() -> 42, 23, 34, 42, 42 -// gas irOptimized: 110966 +// gas irOptimized: 110845 // gas legacy: 112021 // gas legacyOptimized: 110548 diff --git a/test/libsolidity/semanticTests/structs/structs.sol b/test/libsolidity/semanticTests/structs/structs.sol index 3356eac16..412b71d39 100644 --- a/test/libsolidity/semanticTests/structs/structs.sol +++ b/test/libsolidity/semanticTests/structs/structs.sol @@ -32,7 +32,7 @@ contract test { // ---- // check() -> false // set() -> -// gas irOptimized: 134432 +// gas irOptimized: 134411 // gas legacy: 135277 // gas legacyOptimized: 134064 // check() -> true diff --git a/test/libsolidity/semanticTests/userDefinedValueType/calldata.sol b/test/libsolidity/semanticTests/userDefinedValueType/calldata.sol index 56ad74c54..3f4309c86 100644 --- a/test/libsolidity/semanticTests/userDefinedValueType/calldata.sol +++ b/test/libsolidity/semanticTests/userDefinedValueType/calldata.sol @@ -51,12 +51,12 @@ contract C { // compileViaYul: also // ---- // test_f() -> true -// gas irOptimized: 122364 -// gas legacy: 126168 -// gas legacyOptimized: 123199 +// gas irOptimized: 122334 +// gas legacy: 126150 +// gas legacyOptimized: 123163 // test_g() -> true // gas irOptimized: 95980 -// gas legacy: 101311 +// gas legacy: 101281 // gas legacyOptimized: 96566 // addresses(uint256): 0 -> 0x18 // addresses(uint256): 1 -> 0x19 diff --git a/test/libsolidity/semanticTests/userDefinedValueType/calldata_to_storage.sol b/test/libsolidity/semanticTests/userDefinedValueType/calldata_to_storage.sol index 433d1969c..0305fd473 100644 --- a/test/libsolidity/semanticTests/userDefinedValueType/calldata_to_storage.sol +++ b/test/libsolidity/semanticTests/userDefinedValueType/calldata_to_storage.sol @@ -25,7 +25,7 @@ contract C { // ---- // s() -> 0, 0, 0x00, 0 // f((uint8,uint16,bytes2,uint8)): 1, 0xff, "ab", 15 -> -// gas irOptimized: 44786 +// gas irOptimized: 44405 // gas legacy: 47200 // gas legacyOptimized: 44923 // s() -> 1, 0xff, 0x6162000000000000000000000000000000000000000000000000000000000000, 15 diff --git a/test/libsolidity/semanticTests/userDefinedValueType/erc20.sol b/test/libsolidity/semanticTests/userDefinedValueType/erc20.sol index c2c5f3cdc..aea108e2b 100644 --- a/test/libsolidity/semanticTests/userDefinedValueType/erc20.sol +++ b/test/libsolidity/semanticTests/userDefinedValueType/erc20.sol @@ -115,8 +115,8 @@ contract ERC20 { // ---- // constructor() // ~ emit Transfer(address,address,uint256): #0x00, #0x1212121212121212121212121212120000000012, 0x14 -// gas irOptimized: 423885 -// gas legacy: 861559 +// gas irOptimized: 423453 +// gas legacy: 860880 // gas legacyOptimized: 420959 // totalSupply() -> 20 // gas irOptimized: 23415 diff --git a/test/libsolidity/semanticTests/userDefinedValueType/memory_to_storage.sol b/test/libsolidity/semanticTests/userDefinedValueType/memory_to_storage.sol index 04e993682..b250bea87 100644 --- a/test/libsolidity/semanticTests/userDefinedValueType/memory_to_storage.sol +++ b/test/libsolidity/semanticTests/userDefinedValueType/memory_to_storage.sol @@ -25,7 +25,7 @@ contract C { // ---- // s() -> 0, 0, 0x00, 0 // f((uint8,uint16,bytes2,uint8)): 1, 0xff, "ab", 15 -> -// gas irOptimized: 44536 +// gas irOptimized: 44473 // gas legacy: 46213 // gas legacyOptimized: 44671 // s() -> 1, 0xff, 0x6162000000000000000000000000000000000000000000000000000000000000, 15 diff --git a/test/libsolidity/semanticTests/various/address_code.sol b/test/libsolidity/semanticTests/various/address_code.sol index 38e0fb13f..594adea40 100644 --- a/test/libsolidity/semanticTests/various/address_code.sol +++ b/test/libsolidity/semanticTests/various/address_code.sol @@ -18,8 +18,8 @@ contract C { // ---- // constructor() -> // gas irOptimized: 199723 -// gas legacy: 241124 -// gas legacyOptimized: 155549 +// gas legacy: 240889 +// gas legacyOptimized: 155314 // initCode() -> 0x20, 0 // f() -> true // g() -> 0 diff --git a/test/libsolidity/semanticTests/various/contract_binary_dependencies.sol b/test/libsolidity/semanticTests/various/contract_binary_dependencies.sol index 57942979a..806138562 100644 --- a/test/libsolidity/semanticTests/various/contract_binary_dependencies.sol +++ b/test/libsolidity/semanticTests/various/contract_binary_dependencies.sol @@ -21,4 +21,4 @@ contract C { // compileViaYul: also // ---- // constructor() -> -// gas irOptimized: 104337 +// gas irOptimized: 102813 diff --git a/test/libsolidity/semanticTests/various/destructuring_assignment.sol b/test/libsolidity/semanticTests/various/destructuring_assignment.sol index cc93152ea..4b253a63e 100644 --- a/test/libsolidity/semanticTests/various/destructuring_assignment.sol +++ b/test/libsolidity/semanticTests/various/destructuring_assignment.sol @@ -36,6 +36,6 @@ contract C { // compileViaYul: also // ---- // f(bytes): 0x20, 0x5, "abcde" -> 0 -// gas irOptimized: 240691 -// gas legacy: 240358 -// gas legacyOptimized: 239682 +// gas irOptimized: 240667 +// gas legacy: 240349 +// gas legacyOptimized: 239673 diff --git a/test/libsolidity/semanticTests/various/erc20.sol b/test/libsolidity/semanticTests/various/erc20.sol index 9ba4e3cb7..9f9084825 100644 --- a/test/libsolidity/semanticTests/various/erc20.sol +++ b/test/libsolidity/semanticTests/various/erc20.sol @@ -98,8 +98,8 @@ contract ERC20 { // ---- // constructor() // ~ emit Transfer(address,address,uint256): #0x00, #0x1212121212121212121212121212120000000012, 0x14 -// gas irOptimized: 419330 -// gas legacy: 833310 +// gas irOptimized: 418910 +// gas legacy: 832643 // gas legacyOptimized: 416135 // totalSupply() -> 20 // gas irOptimized: 23415 diff --git a/test/libsolidity/semanticTests/various/skip_dynamic_types_for_structs.sol b/test/libsolidity/semanticTests/various/skip_dynamic_types_for_structs.sol index 30a2d9f65..9e334c5e5 100644 --- a/test/libsolidity/semanticTests/various/skip_dynamic_types_for_structs.sol +++ b/test/libsolidity/semanticTests/various/skip_dynamic_types_for_structs.sol @@ -23,5 +23,5 @@ contract C { // ---- // g() -> 2, 6 // gas irOptimized: 178812 -// gas legacy: 180762 -// gas legacyOptimized: 179481 +// gas legacy: 180753 +// gas legacyOptimized: 179472 diff --git a/test/libsolidity/semanticTests/various/value_complex.sol b/test/libsolidity/semanticTests/various/value_complex.sol index 5d8bda5dd..78eb2eec7 100644 --- a/test/libsolidity/semanticTests/various/value_complex.sol +++ b/test/libsolidity/semanticTests/various/value_complex.sol @@ -22,7 +22,7 @@ contract test { // compileViaYul: also // ---- // constructor(), 20 wei -> -// gas irOptimized: 192113 +// gas irOptimized: 191249 // gas legacy: 265006 // gas legacyOptimized: 182842 // sendAmount(uint256): 5 -> 8 diff --git a/test/libsolidity/semanticTests/various/value_insane.sol b/test/libsolidity/semanticTests/various/value_insane.sol index 0b2b1735b..4b57d19e6 100644 --- a/test/libsolidity/semanticTests/various/value_insane.sol +++ b/test/libsolidity/semanticTests/various/value_insane.sol @@ -21,7 +21,7 @@ contract test { // compileViaYul: also // ---- // constructor(), 20 wei -> -// gas irOptimized: 194261 +// gas irOptimized: 193397 // gas legacy: 266728 // gas legacyOptimized: 184762 // sendAmount(uint256): 5 -> 8 diff --git a/test/libsolidity/semanticTests/viaYul/array_memory_index_access.sol b/test/libsolidity/semanticTests/viaYul/array_memory_index_access.sol index 6ef403dcc..772c77af2 100644 --- a/test/libsolidity/semanticTests/viaYul/array_memory_index_access.sol +++ b/test/libsolidity/semanticTests/viaYul/array_memory_index_access.sol @@ -28,9 +28,9 @@ contract C { // index(uint256): 10 -> true // index(uint256): 20 -> true // index(uint256): 0xFF -> true -// gas irOptimized: 138410 -// gas legacy: 248854 -// gas legacyOptimized: 152638 +// gas irOptimized: 137645 +// gas legacy: 247324 +// gas legacyOptimized: 149578 // accessIndex(uint256,int256): 10, 1 -> 2 // accessIndex(uint256,int256): 10, 0 -> 1 // accessIndex(uint256,int256): 10, 11 -> FAILURE, hex"4e487b71", 0x32 diff --git a/test/libsolidity/semanticTests/viaYul/array_storage_index_access.sol b/test/libsolidity/semanticTests/viaYul/array_storage_index_access.sol index 24d0e9f14..63096bed6 100644 --- a/test/libsolidity/semanticTests/viaYul/array_storage_index_access.sol +++ b/test/libsolidity/semanticTests/viaYul/array_storage_index_access.sol @@ -19,32 +19,32 @@ contract C { // test_indices(uint256): 1 -> // test_indices(uint256): 129 -> // gas irOptimized: 3032986 -// gas legacy: 3071205 -// gas legacyOptimized: 3011873 +// gas legacy: 3070431 +// gas legacyOptimized: 3010325 // test_indices(uint256): 5 -> // gas irOptimized: 367642 -// gas legacy: 369241 -// gas legacyOptimized: 366149 +// gas legacy: 369211 +// gas legacyOptimized: 366089 // test_indices(uint256): 10 -> // test_indices(uint256): 15 -> // gas irOptimized: 72860 // test_indices(uint256): 0xFF -> // gas irOptimized: 3438610 -// gas legacy: 3514167 -// gas legacyOptimized: 3398107 +// gas legacy: 3512637 +// gas legacyOptimized: 3395047 // test_indices(uint256): 1000 -> // gas irOptimized: 18318372 -// gas legacy: 18617999 -// gas legacyOptimized: 18178944 +// gas legacy: 18611999 +// gas legacyOptimized: 18166944 // test_indices(uint256): 129 -> // gas irOptimized: 2733570 -// gas legacy: 2772735 -// gas legacyOptimized: 2716547 +// gas legacy: 2771961 +// gas legacyOptimized: 2714999 // test_indices(uint256): 128 -> // gas irOptimized: 426682 -// gas legacy: 467272 -// gas legacyOptimized: 418424 +// gas legacy: 466504 +// gas legacyOptimized: 416888 // test_indices(uint256): 1 -> // gas irOptimized: 363074 -// gas legacy: 363407 -// gas legacyOptimized: 361811 +// gas legacy: 363401 +// gas legacyOptimized: 361799 diff --git a/test/libsolidity/semanticTests/viaYul/array_storage_index_zeroed_test.sol b/test/libsolidity/semanticTests/viaYul/array_storage_index_zeroed_test.sol index b2e0cb546..4361001f4 100644 --- a/test/libsolidity/semanticTests/viaYul/array_storage_index_zeroed_test.sol +++ b/test/libsolidity/semanticTests/viaYul/array_storage_index_zeroed_test.sol @@ -54,18 +54,18 @@ contract C { // ---- // test_zeroed_indicies(uint256): 1 -> // test_zeroed_indicies(uint256): 5 -> -// gas irOptimized: 131197 -// gas legacy: 132367 -// gas legacyOptimized: 129586 +// gas irOptimized: 131193 +// gas legacy: 132331 +// gas legacyOptimized: 129514 // test_zeroed_indicies(uint256): 10 -> -// gas irOptimized: 174805 -// gas legacy: 177329 -// gas legacyOptimized: 172224 +// gas irOptimized: 174811 +// gas legacy: 177248 +// gas legacyOptimized: 172062 // test_zeroed_indicies(uint256): 15 -> -// gas irOptimized: 198055 -// gas legacy: 201954 -// gas legacyOptimized: 194604 +// gas irOptimized: 198071 +// gas legacy: 201828 +// gas legacyOptimized: 194352 // test_zeroed_indicies(uint256): 0xFF -> -// gas irOptimized: 6098185 -// gas legacy: 6163149 -// gas legacyOptimized: 6029474 +// gas irOptimized: 6098681 +// gas legacy: 6160863 +// gas legacyOptimized: 6024902 diff --git a/test/libsolidity/semanticTests/viaYul/array_storage_push_empty.sol b/test/libsolidity/semanticTests/viaYul/array_storage_push_empty.sol index 5c7c4cba8..7291e1e34 100644 --- a/test/libsolidity/semanticTests/viaYul/array_storage_push_empty.sol +++ b/test/libsolidity/semanticTests/viaYul/array_storage_push_empty.sol @@ -14,12 +14,12 @@ contract C { // ---- // pushEmpty(uint256): 128 // gas irOptimized: 412570 -// gas legacy: 417287 -// gas legacyOptimized: 399048 +// gas legacy: 416903 +// gas legacyOptimized: 398280 // pushEmpty(uint256): 256 // gas irOptimized: 702558 -// gas legacy: 715083 -// gas legacyOptimized: 688908 +// gas legacy: 714315 +// gas legacyOptimized: 687372 // pushEmpty(uint256): 38869 -> FAILURE # out-of-gas # // gas irOptimized: 100000000 // gas legacy: 100000000 diff --git a/test/libsolidity/semanticTests/viaYul/copy_struct_invalid_ir_bug.sol b/test/libsolidity/semanticTests/viaYul/copy_struct_invalid_ir_bug.sol index 05b7e668b..b2df7d748 100644 --- a/test/libsolidity/semanticTests/viaYul/copy_struct_invalid_ir_bug.sol +++ b/test/libsolidity/semanticTests/viaYul/copy_struct_invalid_ir_bug.sol @@ -23,6 +23,6 @@ contract C { // compileViaYul: also // ---- // f() -> -// gas irOptimized: 112998 -// gas legacy: 112937 -// gas legacyOptimized: 112608 +// gas irOptimized: 112995 +// gas legacy: 112931 +// gas legacyOptimized: 112602 diff --git a/test/libyul/KnowledgeBaseTest.cpp b/test/libyul/KnowledgeBaseTest.cpp index 03cc4cd8d..ac48f962f 100644 --- a/test/libyul/KnowledgeBaseTest.cpp +++ b/test/libyul/KnowledgeBaseTest.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include diff --git a/test/libyul/YulOptimizerTestCommon.cpp b/test/libyul/YulOptimizerTestCommon.cpp index e7711f586..60826665a 100644 --- a/test/libyul/YulOptimizerTestCommon.cpp +++ b/test/libyul/YulOptimizerTestCommon.cpp @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -237,6 +238,15 @@ YulOptimizerTestCommon::YulOptimizerTestCommon( ForLoopInitRewriter::run(*m_context, *m_ast); UnusedAssignEliminator::run(*m_context, *m_ast); }}, + {"unusedStoreEliminator", [&]() { + disambiguate(); + ForLoopInitRewriter::run(*m_context, *m_ast); + ExpressionSplitter::run(*m_context, *m_ast); + SSATransform::run(*m_context, *m_ast); + UnusedStoreEliminator::run(*m_context, *m_ast); + SSAReverser::run(*m_context, *m_ast); + ExpressionJoiner::run(*m_context, *m_ast); + }}, {"equalStoreEliminator", [&]() { disambiguate(); FunctionHoister::run(*m_context, *m_ast); diff --git a/test/libyul/yulOptimizerTests/fullSuite/extcodelength.yul b/test/libyul/yulOptimizerTests/fullSuite/extcodelength.yul new file mode 100644 index 000000000..436f5d5fa --- /dev/null +++ b/test/libyul/yulOptimizerTests/fullSuite/extcodelength.yul @@ -0,0 +1,40 @@ +{ + let _1 := 0 + let value := calldataload(4) + if iszero(eq(value, and(value, sub(shl(160, 1), 1)))) { revert(_1, _1) } + let length := extcodesize(value) + let _2 := 0xffffffffffffffff + if gt(length, _2) { revert(0, 0) } + let _3 := not(31) + let memPtr := mload(64) + let newFreePtr := add(memPtr, and(add(and(add(length, 31), _3), 63), _3)) + if or(gt(newFreePtr, _2), lt(newFreePtr, memPtr)) { revert(0, 0) } + mstore(64, newFreePtr) + mstore(memPtr, length) + + // We aim to optimize this out. + extcodecopy(value, add(memPtr, 32), _1, length) + sstore(_1, mload(memPtr)) +} +// ==== +// EVMVersion: >byzantium +// ---- +// step: fullSuite +// +// { +// { +// let value := calldataload(4) +// if iszero(eq(value, and(value, sub(shl(160, 1), 1)))) { revert(0, 0) } +// let length := extcodesize(value) +// let _1 := 0xffffffffffffffff +// if gt(length, _1) { revert(0, 0) } +// let memPtr := mload(64) +// let _2 := not(31) +// let newFreePtr := add(memPtr, and(add(and(add(length, 31), _2), 63), _2)) +// if or(gt(newFreePtr, _1), lt(newFreePtr, memPtr)) { revert(0, 0) } +// mstore(64, newFreePtr) +// mstore(memPtr, length) +// extcodecopy(value, add(memPtr, 32), 0, length) +// sstore(0, mload(memPtr)) +// } +// } diff --git a/test/libyul/yulOptimizerTests/fullSuite/medium.yul b/test/libyul/yulOptimizerTests/fullSuite/medium.yul index 41b77c115..9a6381d79 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/medium.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/medium.yul @@ -23,13 +23,7 @@ // // { // { -// let p := mload(0x40) -// mstore(0x40, add(p, 0x20)) -// mstore(0x40, add(p, 96)) -// let p_1 := add(p, 128) -// mstore(p_1, 2) -// mstore(0x40, 0x20) -// sstore(0, p_1) +// sstore(0, add(mload(0x40), 128)) // sstore(1, 0x20) // } // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/remove_redundant_assignments_in_switch.yul b/test/libyul/yulOptimizerTests/fullSuite/remove_redundant_assignments_in_switch.yul index a0ac5c36d..317661325 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/remove_redundant_assignments_in_switch.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/remove_redundant_assignments_in_switch.yul @@ -15,6 +15,5 @@ // case 0 { } // case 1 { } // default { invalid() } -// mstore(1, 1) // } // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/stack_compressor_msize.yul b/test/libyul/yulOptimizerTests/fullSuite/stack_compressor_msize.yul index 13683e8e6..75e2ff4c2 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/stack_compressor_msize.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/stack_compressor_msize.yul @@ -52,9 +52,9 @@ // pop(keccak256(gcd(_3, _2), or(gt(not(gcd(_3, _2)), _1), _1))) // mstore(lt(or(gt(_1, or(or(gt(or(or(or(gt(or(gt(_6, _9), _1), _8), _7), _5), _1), _1), _4), _1)), _1), _1), _1) // sstore(not(gcd(_3, _2)), _1) -// sstore(0, 0) // sstore(2, _1) // extcodecopy(_1, msize(), _1, _1) +// sstore(0, 0) // sstore(3, _1) // } // function gcd(_a, _b) -> out diff --git a/test/libyul/yulOptimizerTests/fullSuite/static_array_slot_computation.yul b/test/libyul/yulOptimizerTests/fullSuite/static_array_slot_computation.yul index c5f4aa466..72c09d3dc 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/static_array_slot_computation.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/static_array_slot_computation.yul @@ -39,7 +39,6 @@ // mstore(4, 0x32) // revert(_1, 0x24) // } -// mstore(_1, _1) // sstore(0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56d, 0x05) // } // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/storage.yul b/test/libyul/yulOptimizerTests/fullSuite/storage.yul index 7b3360847..a60b3d348 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/storage.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/storage.yul @@ -8,7 +8,6 @@ // // { // { -// sstore(4, 5) // sstore(4, 3) // sstore(8, 3) // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner.yul b/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner.yul index b7f0b4afb..6f82ab27a 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner.yul @@ -20,7 +20,6 @@ // { // { // let out1, out2 := foo(sload(32)) -// sstore(0, out1) // sstore(0, out2) // let out1_1, out2_1 := foo(sload(8)) // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_loop.yul b/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_loop.yul index ee648f80f..7955ee12e 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_loop.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_loop.yul @@ -18,9 +18,9 @@ // { // { // f() +// f() +// f() // sstore(0, 1) -// f() -// f() // } // function f() // { diff --git a/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_recursion.yul b/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_recursion.yul index c3b75e84e..92d251cab 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_recursion.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_recursion.yul @@ -18,7 +18,6 @@ // { // let x, y, z := f() // sstore(0, x) -// sstore(1, y) // sstore(1, z) // } // function f() -> x, y, z diff --git a/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_return.yul b/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_return.yul index 14f0137cb..b066d998b 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_return.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_return.yul @@ -22,8 +22,6 @@ // { // { // let out1, out2 := foo(sload(32)) -// sstore(0, out1) -// sstore(0, out2) // sstore(0, 0) // let out1_1, out2_1 := foo(sload(8)) // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_simple.yul b/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_simple.yul index 68620cc96..785840baa 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_simple.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_simple.yul @@ -16,9 +16,9 @@ // { // { // f() +// f() +// f() // sstore(0, 1) -// f() -// f() // } // function f() // { diff --git a/test/libyul/yulOptimizerTests/unusedStoreEliminator/call_does_not_need_to_write.yul b/test/libyul/yulOptimizerTests/unusedStoreEliminator/call_does_not_need_to_write.yul new file mode 100644 index 000000000..eeff779f8 --- /dev/null +++ b/test/libyul/yulOptimizerTests/unusedStoreEliminator/call_does_not_need_to_write.yul @@ -0,0 +1,24 @@ +{ + mstore(0, 1) + let x := call( + 0, + 0, + 0, + 0, + 0, + 0, + 0x32 // length is only a max length, so there is no guarantee that the mstore above is overwritten. + ) + sstore(0, mload(0)) +} + +// ---- +// step: unusedStoreEliminator +// +// { +// { +// mstore(0, 1) +// let x := call(0, 0, 0, 0, 0, 0, 0x32) +// sstore(0, mload(0)) +// } +// } diff --git a/test/libyul/yulOptimizerTests/unusedStoreEliminator/covering_calldatacopy.yul b/test/libyul/yulOptimizerTests/unusedStoreEliminator/covering_calldatacopy.yul new file mode 100644 index 000000000..7fd227089 --- /dev/null +++ b/test/libyul/yulOptimizerTests/unusedStoreEliminator/covering_calldatacopy.yul @@ -0,0 +1,59 @@ +{ + let start := calldataload(0x10) + if calldataload(0) { + // not covered + mstore(add(start, 2), 7) + calldatacopy(start, 0, 0x20) + } + if calldataload(1) { + // covered + mstore(add(start, 2), 9) + calldatacopy(add(start, 1), 0, 0x21) + } + if calldataload(2) { + // covered + mstore8(add(start, 2), 7) + calldatacopy(start, 0, 3) + } + if calldataload(3) { + // not covered + mstore8(add(start, 3), 7) + calldatacopy(start, 0, 3) + } + sstore(0, keccak256(start, 0x40)) +} +// ---- +// step: unusedStoreEliminator +// +// { +// { +// let start := calldataload(0x10) +// if calldataload(0) +// { +// let _4 := 7 +// mstore(add(start, 2), _4) +// calldatacopy(start, 0, 0x20) +// } +// if calldataload(1) +// { +// let _11 := 9 +// mstore(add(start, 2), _11) +// let _14 := 0x21 +// let _15 := 0 +// calldatacopy(add(start, 1), _15, _14) +// } +// if calldataload(2) +// { +// let _20 := 7 +// mstore8(add(start, 2), _20) +// calldatacopy(start, 0, 3) +// } +// if calldataload(3) +// { +// let _27 := 7 +// mstore8(add(start, 3), _27) +// calldatacopy(start, 0, 3) +// } +// sstore(0, keccak256(start, 0x40)) +// } +// } diff --git a/test/libyul/yulOptimizerTests/unusedStoreEliminator/covering_calldatacopy_fixed.yul b/test/libyul/yulOptimizerTests/unusedStoreEliminator/covering_calldatacopy_fixed.yul new file mode 100644 index 000000000..47e0b95fa --- /dev/null +++ b/test/libyul/yulOptimizerTests/unusedStoreEliminator/covering_calldatacopy_fixed.yul @@ -0,0 +1,53 @@ +{ + if calldataload(0) { + // not covered + mstore(2, 7) + calldatacopy(0, 0, 0x20) + } + if calldataload(1) { + // covered + mstore(2, 9) + calldatacopy(1, 0, 0x21) + } + if calldataload(2) { + // covered + mstore8(2, 7) + calldatacopy(0, 0, 3) + } + if calldataload(3) { + // not covered + mstore8(3, 7) + calldatacopy(0, 0, 3) + } + sstore(0, keccak256(0, 0x40)) +} +// ---- +// step: unusedStoreEliminator +// +// { +// { +// if calldataload(0) +// { +// mstore(2, 7) +// calldatacopy(0, 0, 0x20) +// } +// if calldataload(1) +// { +// let _10 := 9 +// let _11 := 2 +// calldatacopy(1, 0, 0x21) +// } +// if calldataload(2) +// { +// let _17 := 7 +// let _18 := 2 +// calldatacopy(0, 0, 3) +// } +// if calldataload(3) +// { +// mstore8(3, 7) +// calldatacopy(0, 0, 3) +// } +// sstore(0, keccak256(0, 0x40)) +// } +// } diff --git a/test/libyul/yulOptimizerTests/unusedStoreEliminator/create.yul b/test/libyul/yulOptimizerTests/unusedStoreEliminator/create.yul new file mode 100644 index 000000000..c3183d9ec --- /dev/null +++ b/test/libyul/yulOptimizerTests/unusedStoreEliminator/create.yul @@ -0,0 +1,17 @@ +{ + let x := 5 + sstore(x, 10) + pop(create(0, 0, 0)) + sstore(x, 20) +} +// ---- +// step: unusedStoreEliminator +// +// { +// { +// let x := 5 +// sstore(x, 10) +// pop(create(0, 0, 0)) +// sstore(x, 20) +// } +// } diff --git a/test/libyul/yulOptimizerTests/unusedStoreEliminator/create_inside_function.yul b/test/libyul/yulOptimizerTests/unusedStoreEliminator/create_inside_function.yul new file mode 100644 index 000000000..782c68663 --- /dev/null +++ b/test/libyul/yulOptimizerTests/unusedStoreEliminator/create_inside_function.yul @@ -0,0 +1,22 @@ +{ + let x := 5 + function f() { + pop(create(0, 0, 0)) + } + sstore(x, 10) + f() + sstore(x, 20) +} +// ---- +// step: unusedStoreEliminator +// +// { +// { +// let x := 5 +// sstore(x, 10) +// f() +// sstore(x, 20) +// } +// function f() +// { pop(create(0, 0, 0)) } +// } diff --git a/test/libyul/yulOptimizerTests/unusedStoreEliminator/function_end.yul b/test/libyul/yulOptimizerTests/unusedStoreEliminator/function_end.yul new file mode 100644 index 000000000..cb69be363 --- /dev/null +++ b/test/libyul/yulOptimizerTests/unusedStoreEliminator/function_end.yul @@ -0,0 +1,20 @@ +{ + function f() { + let x := calldataload(2) + mstore(x, 2) + // This cannot be removed because we do not know what happens after the function. + mstore(x, 3) + } +} +// ---- +// step: unusedStoreEliminator +// +// { +// { } +// function f() +// { +// let x := calldataload(2) +// let _2 := 2 +// mstore(x, 3) +// } +// } diff --git a/test/libyul/yulOptimizerTests/unusedStoreEliminator/function_side_effects.yul b/test/libyul/yulOptimizerTests/unusedStoreEliminator/function_side_effects.yul new file mode 100644 index 000000000..25f9355b3 --- /dev/null +++ b/test/libyul/yulOptimizerTests/unusedStoreEliminator/function_side_effects.yul @@ -0,0 +1,55 @@ +{ + function justStop() { return(0, 0) } + function justRevert() { revert(0, 0) } + + let x := 0 + let y := 1 + let a := 0x80 + let b := 7 + let c := 9 + switch calldataload(0) + case 0 + { + sstore(x, y) + mstore(a, b) + justStop() + sstore(x, y) + mstore(a, b) + } + case 1 + { + sstore(x, y) + mstore(a, b) + justRevert() + sstore(x, y) + mstore(a, b) + } +} +// ---- +// step: unusedStoreEliminator +// +// { +// { +// let x := 0 +// let y := 1 +// let a := 0x80 +// let b := 7 +// let c := 9 +// switch calldataload(0) +// case 0 { +// sstore(x, y) +// mstore(a, b) +// justStop() +// sstore(x, y) +// } +// case 1 { +// mstore(a, b) +// justRevert() +// sstore(x, y) +// } +// } +// function justStop() +// { return(0, 0) } +// function justRevert() +// { revert(0, 0) } +// } diff --git a/test/libyul/yulOptimizerTests/unusedStoreEliminator/function_side_effects_2.yul b/test/libyul/yulOptimizerTests/unusedStoreEliminator/function_side_effects_2.yul new file mode 100644 index 000000000..843f7f6e9 --- /dev/null +++ b/test/libyul/yulOptimizerTests/unusedStoreEliminator/function_side_effects_2.yul @@ -0,0 +1,28 @@ +{ + let x := 0 + let y := 1 + sstore(x, y) + f() + sstore(x, y) + function f() { + // prevent inlining + f() + return(0, 0) + } + } +// ---- +// step: unusedStoreEliminator +// +// { +// { +// let x := 0 +// let y := 1 +// f() +// sstore(x, y) +// } +// function f() +// { +// f() +// return(0, 0) +// } +// } diff --git a/test/libyul/yulOptimizerTests/unusedStoreEliminator/if_overwrite_all_branches.yul b/test/libyul/yulOptimizerTests/unusedStoreEliminator/if_overwrite_all_branches.yul new file mode 100644 index 000000000..7054dc255 --- /dev/null +++ b/test/libyul/yulOptimizerTests/unusedStoreEliminator/if_overwrite_all_branches.yul @@ -0,0 +1,20 @@ +{ + let c := calldataload(0) + // This store will be overwritten in all branches and thus can be removed. + sstore(c, 1) + if c { + sstore(c, 2) + } + sstore(c, 3) +} +// ---- +// step: unusedStoreEliminator +// +// { +// { +// let c := calldataload(0) +// let _2 := 1 +// if c { let _3 := 2 } +// sstore(c, 3) +// } +// } diff --git a/test/libyul/yulOptimizerTests/unusedStoreEliminator/leave.yul b/test/libyul/yulOptimizerTests/unusedStoreEliminator/leave.yul new file mode 100644 index 000000000..92a751554 --- /dev/null +++ b/test/libyul/yulOptimizerTests/unusedStoreEliminator/leave.yul @@ -0,0 +1,23 @@ +{ + function f() { + mstore(0, 5) + if calldataload(0) { leave } + mstore(0x20, 5) + revert(0, 0) + } + f() +} +// ---- +// step: unusedStoreEliminator +// +// { +// { f() } +// function f() +// { +// mstore(0, 5) +// if calldataload(0) { leave } +// let _5 := 5 +// let _6 := 0x20 +// revert(0, 0) +// } +// } diff --git a/test/libyul/yulOptimizerTests/unusedStoreEliminator/memoryguard.yul b/test/libyul/yulOptimizerTests/unusedStoreEliminator/memoryguard.yul new file mode 100644 index 000000000..466cd02e5 --- /dev/null +++ b/test/libyul/yulOptimizerTests/unusedStoreEliminator/memoryguard.yul @@ -0,0 +1,24 @@ +{ + mstore(0x40, memoryguard(100)) + let free_mem_ptr := mload(0x40) + // redundant + mstore(free_mem_ptr, 100) + // redundant + mstore8(add(free_mem_ptr, 31), 200) + mstore(free_mem_ptr, 300) + return(free_mem_ptr, add(free_mem_ptr, 100)) +} +// ---- +// step: unusedStoreEliminator +// +// { +// { +// mstore(0x40, memoryguard(100)) +// let free_mem_ptr := mload(0x40) +// let _4 := 100 +// let _5 := 200 +// mstore8(add(free_mem_ptr, 31), _5) +// mstore(free_mem_ptr, 300) +// return(free_mem_ptr, add(free_mem_ptr, 100)) +// } +// } diff --git a/test/libyul/yulOptimizerTests/unusedStoreEliminator/mload.yul b/test/libyul/yulOptimizerTests/unusedStoreEliminator/mload.yul new file mode 100644 index 000000000..717332472 --- /dev/null +++ b/test/libyul/yulOptimizerTests/unusedStoreEliminator/mload.yul @@ -0,0 +1,20 @@ +{ + let zero := 0 + mstore(zero, 5) + let x := mload(zero) + mstore(zero, 8) + let y := mload(zero) + sstore(zero, y) +} +// ---- +// step: unusedStoreEliminator +// +// { +// { +// let zero := 0 +// mstore(zero, 5) +// let x := mload(zero) +// mstore(zero, 8) +// sstore(zero, mload(zero)) +// } +// } diff --git a/test/libyul/yulOptimizerTests/unusedStoreEliminator/no_storage_inside_function.yul b/test/libyul/yulOptimizerTests/unusedStoreEliminator/no_storage_inside_function.yul new file mode 100644 index 000000000..524b328e9 --- /dev/null +++ b/test/libyul/yulOptimizerTests/unusedStoreEliminator/no_storage_inside_function.yul @@ -0,0 +1,27 @@ +{ + function f() -> r { + r := mload(0x20) + } + let x := 5 + sstore(x, 10) // should be removed + mstore(0, 42) // could be removed, but will probably stay? + pop(f()) + sstore(x, 10) +} +// ---- +// step: unusedStoreEliminator +// +// { +// { +// let x := 5 +// let _2 := 10 +// mstore(0, 42) +// pop(f()) +// sstore(x, 10) +// } +// function f() -> r +// { +// r := mload(0x20) +// let r_7 := r +// } +// } diff --git a/test/libyul/yulOptimizerTests/unusedStoreEliminator/overflow.yul b/test/libyul/yulOptimizerTests/unusedStoreEliminator/overflow.yul new file mode 100644 index 000000000..dda59873c --- /dev/null +++ b/test/libyul/yulOptimizerTests/unusedStoreEliminator/overflow.yul @@ -0,0 +1,18 @@ +{ + let x := 0 + + calldatacopy(0, 0, 115792089237316195423570985008687907853269984665640564039457584007913129639935) + mstore(x, 20) + return(0, 32) +} +// ---- +// step: unusedStoreEliminator +// +// { +// { +// let x := 0 +// calldatacopy(0, 0, 115792089237316195423570985008687907853269984665640564039457584007913129639935) +// mstore(x, 20) +// return(0, 32) +// } +// } diff --git a/test/libyul/yulOptimizerTests/unusedStoreEliminator/overlapping.yul b/test/libyul/yulOptimizerTests/unusedStoreEliminator/overlapping.yul new file mode 100644 index 000000000..78179dc3e --- /dev/null +++ b/test/libyul/yulOptimizerTests/unusedStoreEliminator/overlapping.yul @@ -0,0 +1,21 @@ +{ + let _1 := 0 + if callvalue() { revert(_1, _1) } + mstore(_1, shl(224, 0x4e487b71)) + mstore(4, 0x32) + revert(_1, 0x24) +} +// ==== +// EVMVersion: >=constantinople +// ---- +// step: unusedStoreEliminator +// +// { +// { +// let _1 := 0 +// if callvalue() { revert(_1, _1) } +// mstore(_1, shl(224, 0x4e487b71)) +// mstore(4, 0x32) +// revert(_1, 0x24) +// } +// } diff --git a/test/libyul/yulOptimizerTests/unusedStoreEliminator/overlapping_small.yul b/test/libyul/yulOptimizerTests/unusedStoreEliminator/overlapping_small.yul new file mode 100644 index 000000000..2950a04ce --- /dev/null +++ b/test/libyul/yulOptimizerTests/unusedStoreEliminator/overlapping_small.yul @@ -0,0 +1,27 @@ +{ + let _1 := 0 + let _2 := callvalue() + let _3 := 0x4e487b71 + let _4 := 224 + let _5 := 7 + mstore(_1, _5) + let _6 := 0x32 + let _7 := 4 + mstore(_7, _6) + let _8 := 0x24 + revert(_1, _8) +} +// ---- +// step: unusedStoreEliminator +// +// { +// { +// let _1 := 0 +// let _2 := callvalue() +// let _3 := 0x4e487b71 +// let _4 := 224 +// mstore(_1, 7) +// mstore(4, 0x32) +// revert(_1, 0x24) +// } +// } diff --git a/test/libyul/yulOptimizerTests/unusedStoreEliminator/remove_before_revert.yul b/test/libyul/yulOptimizerTests/unusedStoreEliminator/remove_before_revert.yul new file mode 100644 index 000000000..e7777964c --- /dev/null +++ b/test/libyul/yulOptimizerTests/unusedStoreEliminator/remove_before_revert.yul @@ -0,0 +1,21 @@ +{ + let c := calldataload(0) + mstore(c, 4) + if c { + sstore(c, 2) + } + let d := 0 + revert(d, d) +} +// ---- +// step: unusedStoreEliminator +// +// { +// { +// let c := calldataload(0) +// let _2 := 4 +// if c { let _3 := 2 } +// let d := 0 +// revert(d, d) +// } +// } diff --git a/test/libyul/yulOptimizerTests/unusedStoreEliminator/unaligned_access.yul b/test/libyul/yulOptimizerTests/unusedStoreEliminator/unaligned_access.yul new file mode 100644 index 000000000..3bfd558fe --- /dev/null +++ b/test/libyul/yulOptimizerTests/unusedStoreEliminator/unaligned_access.yul @@ -0,0 +1,17 @@ +{ + let zero := 0 + mstore(zero, 0x1234) + mstore(4, 0x456) + revert(zero, 5) +} +// ---- +// step: unusedStoreEliminator +// +// { +// { +// let zero := 0 +// mstore(zero, 0x1234) +// mstore(4, 0x456) +// revert(zero, 5) +// } +// } diff --git a/test/libyul/yulOptimizerTests/unusedStoreEliminator/unknown_length2.yul b/test/libyul/yulOptimizerTests/unusedStoreEliminator/unknown_length2.yul new file mode 100644 index 000000000..db5f060a6 --- /dev/null +++ b/test/libyul/yulOptimizerTests/unusedStoreEliminator/unknown_length2.yul @@ -0,0 +1,33 @@ +{ + let a + switch calldataload(0) + case 0 { a := calldataload(9) } + case 1 { a := calldataload(10) } + + calldatacopy(0x20, 0, a) + let x := mload(0) + sstore(0, x) +} +// ---- +// step: unusedStoreEliminator +// +// { +// { +// let a_9 +// let a := a_9 +// switch calldataload(0) +// case 0 { +// a := calldataload(9) +// let a_10 := a +// } +// case 1 { +// let a_12 := a +// a := calldataload(10) +// let a_11 := a +// } +// let a_13 := a +// let _5 := 0 +// let _6 := 0x20 +// sstore(0, mload(0)) +// } +// } diff --git a/test/libyul/yulOptimizerTests/unusedStoreEliminator/unrelated_relative.yul b/test/libyul/yulOptimizerTests/unusedStoreEliminator/unrelated_relative.yul new file mode 100644 index 000000000..b0b42060f --- /dev/null +++ b/test/libyul/yulOptimizerTests/unusedStoreEliminator/unrelated_relative.yul @@ -0,0 +1,23 @@ +{ + let c := calldataload(0) + mstore(c, 4) + mstore(add(c, 0x20), 8) + sstore(0, mload(c)) + mstore(c, 9) + mstore(add(c, 0x20), 20) +} +// ---- +// step: unusedStoreEliminator +// +// { +// { +// let c := calldataload(0) +// mstore(c, 4) +// let _3 := 8 +// let _5 := add(c, 0x20) +// sstore(0, mload(c)) +// let _8 := 9 +// let _9 := 20 +// let _11 := add(c, 0x20) +// } +// } diff --git a/test/libyul/yulOptimizerTests/unusedStoreEliminator/write_before_recursion.yul b/test/libyul/yulOptimizerTests/unusedStoreEliminator/write_before_recursion.yul new file mode 100644 index 000000000..855ae8325 --- /dev/null +++ b/test/libyul/yulOptimizerTests/unusedStoreEliminator/write_before_recursion.yul @@ -0,0 +1,27 @@ +{ + sstore(0, 1) + mstore(0, 2) + f() + function f() { + g() + } + function g() { + f() + } +} +// ---- +// step: unusedStoreEliminator +// +// { +// { +// let _1 := 1 +// let _2 := 0 +// let _3 := 2 +// let _4 := 0 +// f() +// } +// function f() +// { g() } +// function g() +// { f() } +// } diff --git a/test/yulPhaser/Chromosome.cpp b/test/yulPhaser/Chromosome.cpp index 1b1e8bed5..90e278f42 100644 --- a/test/yulPhaser/Chromosome.cpp +++ b/test/yulPhaser/Chromosome.cpp @@ -138,7 +138,7 @@ BOOST_AUTO_TEST_CASE(output_operator_should_create_concise_and_unambiguous_strin BOOST_TEST(chromosome.length() == allSteps.size()); BOOST_TEST(chromosome.optimisationSteps() == allSteps); - BOOST_TEST(toString(chromosome) == "flcCUnDEvejsxIOoighFTLMRmVatrpud"); + BOOST_TEST(toString(chromosome) == "flcCUnDEvejsxIOoighFTLMRmVatrpuSd"); } BOOST_AUTO_TEST_CASE(optimisationSteps_should_translate_chromosomes_genes_to_optimisation_step_names)