From 85d1a57e65a1490db812a4531fc0b85d42ad8669 Mon Sep 17 00:00:00 2001 From: hrkrshnn Date: Mon, 3 Jan 2022 15:19:25 +0530 Subject: [PATCH] Added more tests. Updated chromosome. Remove unused headers. --- libyul/optimiser/EqualStoreEliminator.cpp | 7 --- libyul/optimiser/UnusedStoreBase.cpp | 1 - .../externalContracts/deposit_contract.sol | 2 +- .../equalStoreEliminator/branching.yul | 25 +++++++++ .../equalStoreEliminator/forloop.yul | 20 +++++++ .../equalStoreEliminator/functionbody.yul | 56 +++++++++++++++++++ .../indirect_inferrence.yul | 24 ++++++++ .../equalStoreEliminator/value_change.yul | 18 ++++++ .../equalStoreEliminator/verbatim.yul | 27 +++++++++ test/yulPhaser/Chromosome.cpp | 2 +- 10 files changed, 172 insertions(+), 10 deletions(-) create mode 100644 test/libyul/yulOptimizerTests/equalStoreEliminator/branching.yul create mode 100644 test/libyul/yulOptimizerTests/equalStoreEliminator/forloop.yul create mode 100644 test/libyul/yulOptimizerTests/equalStoreEliminator/functionbody.yul create mode 100644 test/libyul/yulOptimizerTests/equalStoreEliminator/indirect_inferrence.yul create mode 100644 test/libyul/yulOptimizerTests/equalStoreEliminator/value_change.yul create mode 100644 test/libyul/yulOptimizerTests/equalStoreEliminator/verbatim.yul diff --git a/libyul/optimiser/EqualStoreEliminator.cpp b/libyul/optimiser/EqualStoreEliminator.cpp index c89567868..dcba98ce4 100644 --- a/libyul/optimiser/EqualStoreEliminator.cpp +++ b/libyul/optimiser/EqualStoreEliminator.cpp @@ -25,16 +25,9 @@ #include #include #include -#include -#include #include #include -#include -#include - -#include - using namespace std; using namespace solidity; using namespace solidity::util; diff --git a/libyul/optimiser/UnusedStoreBase.cpp b/libyul/optimiser/UnusedStoreBase.cpp index 73f957ecc..8e34d172f 100644 --- a/libyul/optimiser/UnusedStoreBase.cpp +++ b/libyul/optimiser/UnusedStoreBase.cpp @@ -23,7 +23,6 @@ #include #include -#include #include #include diff --git a/test/libsolidity/semanticTests/externalContracts/deposit_contract.sol b/test/libsolidity/semanticTests/externalContracts/deposit_contract.sol index ed9a07f7f..7f5799805 100644 --- a/test/libsolidity/semanticTests/externalContracts/deposit_contract.sol +++ b/test/libsolidity/semanticTests/externalContracts/deposit_contract.sol @@ -178,7 +178,7 @@ contract DepositContract is IDepositContract, ERC165 { // compileViaYul: also // ---- // constructor() -// gas irOptimized: 1558001 +// gas irOptimized: 1557137 // gas legacy: 2436584 // gas legacyOptimized: 1776483 // supportsInterface(bytes4): 0x0 -> 0 diff --git a/test/libyul/yulOptimizerTests/equalStoreEliminator/branching.yul b/test/libyul/yulOptimizerTests/equalStoreEliminator/branching.yul new file mode 100644 index 000000000..63f0d38e4 --- /dev/null +++ b/test/libyul/yulOptimizerTests/equalStoreEliminator/branching.yul @@ -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)) +// } +// } diff --git a/test/libyul/yulOptimizerTests/equalStoreEliminator/forloop.yul b/test/libyul/yulOptimizerTests/equalStoreEliminator/forloop.yul new file mode 100644 index 000000000..ccd7dd40b --- /dev/null +++ b/test/libyul/yulOptimizerTests/equalStoreEliminator/forloop.yul @@ -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) } +// } diff --git a/test/libyul/yulOptimizerTests/equalStoreEliminator/functionbody.yul b/test/libyul/yulOptimizerTests/equalStoreEliminator/functionbody.yul new file mode 100644 index 000000000..68839721c --- /dev/null +++ b/test/libyul/yulOptimizerTests/equalStoreEliminator/functionbody.yul @@ -0,0 +1,56 @@ +{ + f(calldataload(0), calldataload(32)) + h(calldataload(64), calldataload(96)) + + function f(a, b) { + // gets removed + sstore(a, b) + g() + sstore(a, b) + } + + function g() { + pop(staticcall(0, 0, 0, 0, 0, 0)) + } + + function h(a_, b_) { + // cannot be removed + sstore(a_, b_) + i() + sstore(a_, b_) + } + + function i() { + pop(delegatecall(0, 0, 0, 0, 0, 0)) + } + + +} +// ==== +// EVMVersion: >=byzantium +// ---- +// step: equalStoreEliminator +// +// { +// f(calldataload(0), calldataload(32)) +// h(calldataload(64), calldataload(96)) +// function f(a, b) +// { +// sstore(a, b) +// g() +// } +// function g() +// { +// pop(staticcall(0, 0, 0, 0, 0, 0)) +// } +// function h(a_, b_) +// { +// sstore(a_, b_) +// i() +// sstore(a_, b_) +// } +// function i() +// { +// pop(delegatecall(0, 0, 0, 0, 0, 0)) +// } +// } diff --git a/test/libyul/yulOptimizerTests/equalStoreEliminator/indirect_inferrence.yul b/test/libyul/yulOptimizerTests/equalStoreEliminator/indirect_inferrence.yul new file mode 100644 index 000000000..2b68e6310 --- /dev/null +++ b/test/libyul/yulOptimizerTests/equalStoreEliminator/indirect_inferrence.yul @@ -0,0 +1,24 @@ +{ + let x := calldataload(0) + let y := sload(x) + // both of these can be removed + sstore(x, y) + sstore(x, y) + + let a := x + let b := mload(a) + // both of these can be removed + mstore(a, b) + mstore(a, b) +} +// ==== +// EVMVersion: >=byzantium +// ---- +// step: equalStoreEliminator +// +// { +// let x := calldataload(0) +// let y := sload(x) +// let a := x +// let b := mload(a) +// } diff --git a/test/libyul/yulOptimizerTests/equalStoreEliminator/value_change.yul b/test/libyul/yulOptimizerTests/equalStoreEliminator/value_change.yul new file mode 100644 index 000000000..bd1e08bcd --- /dev/null +++ b/test/libyul/yulOptimizerTests/equalStoreEliminator/value_change.yul @@ -0,0 +1,18 @@ +{ + let x := calldataload(0) + let y := calldataload(32) + sstore(x, y) + y := calldataload(64) + // cannot be removed + sstore(x, y) +} +// ---- +// step: equalStoreEliminator +// +// { +// let x := calldataload(0) +// let y := calldataload(32) +// sstore(x, y) +// y := calldataload(64) +// sstore(x, y) +// } diff --git a/test/libyul/yulOptimizerTests/equalStoreEliminator/verbatim.yul b/test/libyul/yulOptimizerTests/equalStoreEliminator/verbatim.yul new file mode 100644 index 000000000..fcaddd121 --- /dev/null +++ b/test/libyul/yulOptimizerTests/equalStoreEliminator/verbatim.yul @@ -0,0 +1,27 @@ +{ + let a := calldataload(0) + let b := 20 + sstore(a, b) + if calldataload(32) { + sstore(a, b) + pop(staticcall(0, 0, 0, 0, 0, 0)) + verbatim_0i_0o("xyz") + } + 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)) +// verbatim_0i_0o("xyz") +// } +// sstore(a, b) +// } diff --git a/test/yulPhaser/Chromosome.cpp b/test/yulPhaser/Chromosome.cpp index d3e31b5e8..1b1e8bed5 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) == "flcCUnDEvejsxIOoighFTLMRrmVatpud"); + BOOST_TEST(toString(chromosome) == "flcCUnDEvejsxIOoighFTLMRmVatrpud"); } BOOST_AUTO_TEST_CASE(optimisationSteps_should_translate_chromosomes_genes_to_optimisation_step_names)