Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equal store eliminator. #12272

Merged
merged 4 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Language Features:


Compiler Features:
* Yul Optimizer: Remove ``mstore`` and ``sstore`` operations if the slot already contains the same value.



Expand Down
17 changes: 17 additions & 0 deletions docs/internals/optimizer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ on the individual steps and their sequence below.
- :ref:`conditional-unsimplifier`.
- :ref:`control-flow-simplifier`.
- :ref:`dead-code-eliminator`.
- :ref:`equal-store-eliminator`.
- :ref:`equivalent-function-combiner`.
- :ref:`expression-joiner`.
- :ref:`expression-simplifier`.
Expand Down Expand Up @@ -938,6 +939,22 @@ we require ForLoopInitRewriter to run before this step.

Prerequisite: ForLoopInitRewriter, Function Hoister, Function Grouper

.. _equal-store-eliminator:

EqualStoreEliminator
^^^^^^^^^^^^^^^^^^^^

This steps removes ``mstore(k, v)`` and ``sstore(k, v)`` calls if
there was a previous call to ``mstore(k, v)`` / ``sstore(k, v)``,
no other store in between and the values of ``k`` and ``v`` did not change.

This simple step is effective if run after the SSA transform and the
Common Subexpression Eliminator, because SSA will make sure that the variables
will not change and the Common Subexpression Eliminator re-uses exactly the same
variable if the value is known to be the same.

Prerequisites: Disambiguator, ForLoopInitRewriter

.. _unused-pruner:

UnusedPruner
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/interface/OptimiserSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct OptimiserSettings
static char constexpr DefaultYulOptimiserSteps[] =
"dhfoDgvulfnTUtnIf" // None of these can make stack problems worse
"["
"xa[r]scLM" // Turn into SSA and simplify
"xa[r]EscLM" // Turn into SSA and simplify
"cCTUtTOntnfDIul" // Perform structural simplification
"Lcul" // Simplify again
"Vcul [j]" // Reverse SSA
Expand Down
2 changes: 2 additions & 0 deletions libyul/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ add_library(yul
optimiser/DeadCodeEliminator.h
optimiser/Disambiguator.cpp
optimiser/Disambiguator.h
optimiser/EqualStoreEliminator.cpp
optimiser/EqualStoreEliminator.h
optimiser/EquivalentFunctionDetector.cpp
optimiser/EquivalentFunctionDetector.h
optimiser/EquivalentFunctionCombiner.cpp
Expand Down
70 changes: 70 additions & 0 deletions libyul/optimiser/EqualStoreEliminator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
// SPDX-License-Identifier: GPL-3.0
/**
* Optimisation stage that removes mstore and sstore operations if they store the same
* value that is already known to be in that slot.
*/

#include <libyul/optimiser/EqualStoreEliminator.h>

#include <libyul/optimiser/CallGraphGenerator.h>
#include <libyul/optimiser/OptimizerUtilities.h>
#include <libyul/optimiser/Semantics.h>
#include <libyul/AST.h>
#include <libyul/Utilities.h>

using namespace std;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::evmasm;
using namespace solidity::yul;

void EqualStoreEliminator::run(OptimiserStepContext const& _context, Block& _ast)
{
EqualStoreEliminator eliminator{
_context.dialect,
SideEffectsPropagator::sideEffects(_context.dialect, CallGraphGenerator::callGraph(_ast))
};
eliminator(_ast);

StatementRemover remover{eliminator.m_pendingRemovals};
remover(_ast);
}

void EqualStoreEliminator::visit(Statement& _statement)
{
// No need to consider potential changes through complex arguments since
// isSimpleStore only returns something if the arguments are identifiers.
if (ExpressionStatement const* expression = get_if<ExpressionStatement>(&_statement))
{
if (auto vars = isSimpleStore(StoreLoadLocation::Storage, *expression))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to the PR changes, but the name isSimpleStore is very confusing given that it returns two variables. Without reading the docs to that function I'd have no idea what's going on here...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like extractStoreArguments might be more understandable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that removing auto might help.

Too bad that a destructuring assignment like auto [location, value] = won't work here due to the optional.

{
if (auto const* currentValue = valueOrNullptr(m_storage, vars->first))
if (*currentValue == vars->second)
m_pendingRemovals.insert(&_statement);
Comment on lines +58 to +59
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this condition a bit too simple?

The docstring says that this is best used when there are no literal arguments. So let's take this code:

    mstore(0, 0)
    mstore(0, 0)

ExpressionSplitter seems to remove literal arguments and it turns the code to this:

    let _1 := 0
    let _2 := 0
    mstore(_2, _1)
    let _3 := 0
    let _4 := 0
    mstore(_4, _3)

but it this would defeat this optimization.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you also need to call the CSE to make this work properly, but I'm actually currently wondering whether we check somewhere that the value is an ssa variable with a movable value, this should be another condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah no, it's fine - we only replace variables by variables and we clear everything whenever there was an assignment to the variable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you mention it in the docstring? A comment in this function would not hurt either. This kind of assumption is not easy to notice other than from the fact that the code looks way too simple for that it does so there must be some "catch" somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly do you want me to mention? These are all properties of the base class.

}
else if (auto vars = isSimpleStore(StoreLoadLocation::Memory, *expression))
{
if (auto const* currentValue = valueOrNullptr(m_memory, vars->first))
if (*currentValue == vars->second)
m_pendingRemovals.insert(&_statement);
}
}

DataFlowAnalyzer::visit(_statement);
}
60 changes: 60 additions & 0 deletions libyul/optimiser/EqualStoreEliminator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
// SPDX-License-Identifier: GPL-3.0
/**
* Optimisation stage that removes mstore and sstore operations if they store the same
* value that is already known to be in that slot.
*/

#pragma once

#include <libyul/optimiser/DataFlowAnalyzer.h>
#include <libyul/optimiser/OptimiserStep.h>

namespace solidity::yul
{

/**
* Optimisation stage that removes mstore and sstore operations if they store the same
* value that is already known to be in that slot.
*
* Works best if the code is in SSA form - without literal arguments.
cameel marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd make it more explicit. "Works best" does not really tell me what I can expect if my code does not satisfy this.

Suggested change
* Works best if the code is in SSA form - without literal arguments.
* Does not optimize parts of code with variables not in SSA form or with calls with literal arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that is exactly what is written there, isn't it? We use this wording in all the other steps as well.

*
* Prerequisite: Disambiguator, ForLoopInitRewriter.
*/
class EqualStoreEliminator: public DataFlowAnalyzer
{
public:
static constexpr char const* name{"EqualStoreEliminator"};
static void run(OptimiserStepContext const&, Block& _ast);

private:
EqualStoreEliminator(
Dialect const& _dialect,
std::map<YulString, SideEffects> _functionSideEffects
):
DataFlowAnalyzer(_dialect, std::move(_functionSideEffects))
{}

protected:
using ASTModifier::visit;
void visit(Statement& _statement) override;

std::set<Statement const*> m_pendingRemovals;
};

}
15 changes: 15 additions & 0 deletions libyul/optimiser/OptimizerUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,18 @@ optional<evmasm::Instruction> yul::toEVMInstruction(Dialect const& _dialect, Yul
return builtin->instruction;
return nullopt;
}

void StatementRemover::operator()(Block& _block)
{
util::iterateReplacing(
_block.statements,
[&](Statement& _statement) -> std::optional<vector<Statement>>
{
if (m_toRemove.count(&_statement))
return {vector<Statement>{}};
else
return nullopt;
}
);
ASTModifier::operator()(_block);
}
11 changes: 11 additions & 0 deletions libyul/optimiser/OptimizerUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <libyul/ASTForward.h>
#include <libyul/Dialect.h>
#include <libyul/YulString.h>
#include <libyul/optimiser/ASTWalker.h>

#include <optional>

Expand All @@ -48,4 +49,14 @@ bool isRestrictedIdentifier(Dialect const& _dialect, YulString const& _identifie
/// Helper function that returns the instruction, if the `_name` is a BuiltinFunction
std::optional<evmasm::Instruction> toEVMInstruction(Dialect const& _dialect, YulString const& _name);

class StatementRemover: public ASTModifier
{
public:
explicit StatementRemover(std::set<Statement const*> const& _toRemove): m_toRemove(_toRemove) {}

void operator()(Block& _block) override;
private:
std::set<Statement const*> const& m_toRemove;
};

}
3 changes: 3 additions & 0 deletions libyul/optimiser/Suite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <libyul/optimiser/DeadCodeEliminator.h>
#include <libyul/optimiser/FunctionGrouper.h>
#include <libyul/optimiser/FunctionHoister.h>
#include <libyul/optimiser/EqualStoreEliminator.h>
#include <libyul/optimiser/EquivalentFunctionCombiner.h>
#include <libyul/optimiser/ExpressionSplitter.h>
#include <libyul/optimiser/ExpressionJoiner.h>
Expand Down Expand Up @@ -204,6 +205,7 @@ map<string, unique_ptr<OptimiserStep>> const& OptimiserSuite::allSteps()
ConditionalUnsimplifier,
ControlFlowSimplifier,
DeadCodeEliminator,
EqualStoreEliminator,
EquivalentFunctionCombiner,
ExpressionInliner,
ExpressionJoiner,
Expand Down Expand Up @@ -244,6 +246,7 @@ map<string, char> const& OptimiserSuite::stepNameToAbbreviationMap()
{ConditionalUnsimplifier::name, 'U'},
{ControlFlowSimplifier::name, 'n'},
{DeadCodeEliminator::name, 'D'},
{EqualStoreEliminator::name, 'E'},
{EquivalentFunctionCombiner::name, 'v'},
{ExpressionInliner::name, 'e'},
{ExpressionJoiner::name, 'j'},
Expand Down
1 change: 1 addition & 0 deletions libyul/optimiser/UnusedAssignEliminator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <libyul/optimiser/UnusedAssignEliminator.h>

#include <libyul/optimiser/Semantics.h>
#include <libyul/optimiser/OptimizerUtilities.h>
#include <libyul/AST.h>

#include <libsolutil/CommonData.h>
Expand Down
15 changes: 0 additions & 15 deletions libyul/optimiser/UnusedStoreBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,3 @@ void UnusedStoreBase::merge(TrackedStores& _target, vector<TrackedStores>&& _sou
merge(_target, move(ts));
_source.clear();
}

void StatementRemover::operator()(Block& _block)
{
util::iterateReplacing(
_block.statements,
[&](Statement& _statement) -> std::optional<vector<Statement>>
{
if (m_toRemove.count(&_statement))
return {vector<Statement>{}};
else
return nullopt;
}
);
ASTModifier::operator()(_block);
}
10 changes: 0 additions & 10 deletions libyul/optimiser/UnusedStoreBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,4 @@ class UnusedStoreBase: public ASTWalker
size_t m_forLoopNestingDepth = 0;
};

class StatementRemover: public ASTModifier
{
public:
explicit StatementRemover(std::set<Statement const*> const& _toRemove): m_toRemove(_toRemove) {}

void operator()(Block& _block) override;
private:
std::set<Statement const*> const& m_toRemove;
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ contract DepositContract is IDepositContract, ERC165 {
// compileViaYul: also
// ----
// constructor()
// gas irOptimized: 1558001
// gas irOptimized: 1557137
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff -u /tmp/develop.yul /tmp/eq.yul
--- /tmp/develop.yul	2022-01-03 17:32:01.880093589 +0530
+++ /tmp/eq.yul	2022-01-03 17:31:28.243155455 +0530
@@ -546,7 +546,6 @@
                 calldatacopy(pos, value0, value1)
                 let _1 := add(pos, value1)
                 mstore(_1, 0)
-                mstore(_1, 0)
                 end := add(_1, 16)
             }
             function calldata_array_index_range_access_bytes_calldata_3157(offset, length) -> offsetOut, lengthOut
@@ -572,8 +571,6 @@
                 let _1 := add(pos, value1)
                 mstore(_1, /** @src 0:6663:6664  "0" */ 0x00)
                 /// @src 0:4559:9399  "contract DepositContract is IDepositContract, ERC165 {..."
-                mstore(_1, /** @src 0:6663:6664  "0" */ 0x00)
-                /// @src 0:4559:9399  "contract DepositContract is IDepositContract, ERC165 {..."
                 end := add(_1, 32)
             }
             function abi_encode_packed_bytes32_bytes_calldata(pos, value0, value1, value2) -> end
@@ -937,7 +934,7 @@
                 mstore8(memory_array_index_access_bytes_3175(memPtr), /** @src 0:9377:9390  "bytesValue[0]" */ byte(/** @src -1:-1:-1 */ 0, /** @src 0:9377:9390  "bytesValue[0]" */ _1))
             }
         }
-        data ".metadata" hex"a364697066735822122006c8a10f3f04d8c69b52af5dbc3a82224acdfaa0224b0f3ed0cf38c99a4f0c7e6c6578706572696d656e74616cf564736f6c637823302e382e31322d63692e323032312e362e32332b636f6d6d69742e36383439373734620062"
+        data ".metadata" hex"a3646970667358221220a5a5d6e1a1822c1fcf45d9e6ac103252bac21d4af4c04b1a690185ad3147faf46c6578706572696d656e74616cf564736f6c63782b302e382e31322d646576656c6f702e323032322e312e332b636f6d6d69742e33633634333238612e6d6f64006a"
     }
 }
 

Diff finished.  Mon Jan  3 17:32:12 2022

Here's the diff!

// gas legacy: 2436584
// gas legacyOptimized: 1776483
// supportsInterface(bytes4): 0x0 -> 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: 111965
// gas irOptimized: 111896
// gas legacy: 113806
// gas legacyOptimized: 111781
// get(uint8): 1 -> 21, 22, 42, 43
Expand Down
4 changes: 2 additions & 2 deletions test/libsolidity/semanticTests/structs/struct_copy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ contract c {
// compileViaYul: also
// ----
// set(uint256): 7 -> true
// gas irOptimized: 110011
// gas irOptimized: 110119
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be working 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assembly is actually shorter. My guess is that the removed mstore instructions makes it impossible for the opcode-based optimizer to remove the multiple keccak calls...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--- /tmp/ir_old.yul	2022-01-03 15:46:30.242337855 +0100
+++ /tmp/ir_opt.yul	2022-01-03 15:41:35.197221133 +0100
@@ -79,34 +79,26 @@
                 mstore(_1, var_k)
                 mstore(0x20, _1)
                 sstore(keccak256(_1, 0x40), 0x01)
-                mstore(_1, var_k)
-                mstore(0x20, _1)
                 sstore(add(keccak256(_1, 0x40), 0x01), 0x03)
-                mstore(_1, var_k)
-                mstore(0x20, _1)
                 sstore(add(keccak256(_1, 0x40), 2), 0x04)
-                mstore(_1, var_k)
-                mstore(0x20, _1)
                 sstore(add(keccak256(_1, 0x40), 0x03), 2)
                 var := 0x01
             }
             function fun_copy(var_from, var_to) -> var_
             {
-                let _1 := 0x00
-                mstore(_1, var_from)
-                mstore(0x20, _1)
-                let dataSlot := keccak256(_1, 0x40)
-                mstore(_1, var_to)
-                mstore(0x20, _1)
-                let dataSlot_1 := keccak256(_1, 0x40)
+                mstore(0x00, var_from)
+                mstore(0x20, 0x00)
+                let dataSlot := keccak256(0x00, 0x40)
+                mstore(0x00, var_to)
+                let dataSlot_1 := keccak256(0x00, 0x40)
                 if iszero(eq(dataSlot_1, dataSlot))
                 {
                     sstore(dataSlot_1, sload(dataSlot))
                     let memberSlot := add(dataSlot_1, 1)
-                    let _2 := add(dataSlot, 1)
-                    if iszero(eq(memberSlot, _2))
+                    let _1 := add(dataSlot, 1)
+                    if iszero(eq(memberSlot, _1))
                     {
-                        sstore(memberSlot, sload(_2))
+                        sstore(memberSlot, sload(_1))
                         sstore(add(dataSlot_1, 2), sload(add(dataSlot, 2)))
                     }
                     sstore(add(dataSlot_1, 3), sload(add(dataSlot, 3)))
@@ -119,18 +111,12 @@
                 mstore(_1, var_k)
                 mstore(0x20, _1)
                 var_a := sload(keccak256(_1, 0x40))
-                mstore(_1, var_k)
-                mstore(0x20, _1)
                 var_x := sload(add(keccak256(_1, 0x40), 1))
-                mstore(_1, var_k)
-                mstore(0x20, _1)
                 var_y := sload(add(keccak256(_1, 0x40), 2))
-                mstore(_1, var_k)
-                mstore(0x20, _1)
                 var_c := sload(add(keccak256(_1, 0x40), 3))
             }
         }
-        data ".metadata" hex"a36469706673582212201575720a9612338487e4ea44beef0f99559f8ddb767d3b3a8f88b30e8203f9ee6c6578706572696d656e74616cf564736f6c634300080c0041"
+        data ".metadata" hex"a36469706673582212201300a8828ade0dfe77d7dbd65f00b07037165a285fa1ba1a0c986a59b74ec9b66c6578706572696d656e74616cf564736f6c634300080c0041"
     }
 }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main change is that zero constants are now inlined, so I would say it's not an issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should perhaps implement evaluating keccak for multi words (at least 2 words).

// gas legacy: 110616
// gas legacyOptimized: 110006
// retrieve(uint256): 7 -> 1, 3, 4, 2
// copy(uint256,uint256): 7, 8 -> true
// gas irOptimized: 118707
// gas irOptimized: 118698
// gas legacy: 119166
// gas legacyOptimized: 118622
// retrieve(uint256): 7 -> 1, 3, 4, 2
Expand Down
6 changes: 6 additions & 0 deletions test/libyul/YulOptimizerTestCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <libyul/optimiser/ConditionalUnsimplifier.h>
#include <libyul/optimiser/ConditionalSimplifier.h>
#include <libyul/optimiser/CommonSubexpressionEliminator.h>
#include <libyul/optimiser/EqualStoreEliminator.h>
#include <libyul/optimiser/EquivalentFunctionCombiner.h>
#include <libyul/optimiser/ExpressionSplitter.h>
#include <libyul/optimiser/FunctionGrouper.h>
Expand Down Expand Up @@ -236,6 +237,11 @@ YulOptimizerTestCommon::YulOptimizerTestCommon(
ForLoopInitRewriter::run(*m_context, *m_ast);
UnusedAssignEliminator::run(*m_context, *m_ast);
}},
{"equalStoreEliminator", [&]() {
disambiguate();
ForLoopInitRewriter::run(*m_context, *m_ast);
EqualStoreEliminator::run(*m_context, *m_ast);
}},
{"ssaPlusCleanup", [&]() {
disambiguate();
ForLoopInitRewriter::run(*m_context, *m_ast);
Expand Down
25 changes: 25 additions & 0 deletions test/libyul/yulOptimizerTests/equalStoreEliminator/branching.yul
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
let a := calldataload(0)
let b := 20
sstore(a, b)
if calldataload(32) {
sstore(a, b)
pop(staticcall(0, 0, 0, 0, 0, 0))
sstore(a, b)
}
sstore(a, b)
}
// ====
// EVMVersion: >=byzantium
// ----
// step: equalStoreEliminator
//
// {
// let a := calldataload(0)
// let b := 20
// sstore(a, b)
// if calldataload(32)
// {
// pop(staticcall(0, 0, 0, 0, 0, 0))
// }
// }
20 changes: 20 additions & 0 deletions test/libyul/yulOptimizerTests/equalStoreEliminator/forloop.yul
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
let x := calldataload(0)
let y := calldataload(1)

sstore(x, y)
for {let a := 1} lt(a, 10) {a := add(a, 1) } {
sstore(x, y)
}
}
// ----
// step: equalStoreEliminator
//
// {
// let x := calldataload(0)
// let y := calldataload(1)
// sstore(x, y)
// let a := 1
// for { } lt(a, 10) { a := add(a, 1) }
// { sstore(x, y) }
// }
Loading