aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rwxr-xr-xtest/cmdlineTests.sh98
-rw-r--r--test/cmdlineTests/too_long_line_multiline.sol13
-rw-r--r--test/cmdlineTests/too_long_line_multiline.sol.err6
-rw-r--r--test/cmdlineTests/too_long_line_multiline.sol.exit1
-rw-r--r--test/libyul/YulOptimizerTest.cpp2
-rw-r--r--test/libyul/objectCompiler/nested_optimizer.yul18
-rw-r--r--test/libyul/objectCompiler/simple_optimizer.yul11
-rw-r--r--test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul76
-rw-r--r--test/libyul/yulOptimizerTests/fullSuite/medium.yul5
-rw-r--r--test/libyul/yulOptimizerTests/rematerialiser/branches_for1.yul12
-rw-r--r--test/libyul/yulOptimizerTests/rematerialiser/branches_for2.yul14
-rw-r--r--test/libyul/yulOptimizerTests/rematerialiser/branches_for_declared_in_init1.yul12
-rw-r--r--test/libyul/yulOptimizerTests/rematerialiser/branches_for_declared_in_init2.yul6
-rw-r--r--test/libyul/yulOptimizerTests/rematerialiser/branches_if.yul14
-rw-r--r--test/libyul/yulOptimizerTests/rematerialiser/cheap_caller.yul16
-rw-r--r--test/libyul/yulOptimizerTests/rematerialiser/do_not_remat_large_amounts_of_code2.yul10
-rw-r--r--test/libyul/yulOptimizerTests/rematerialiser/do_remat_large_amounts_of_code_if_used_once.yul (renamed from test/libyul/yulOptimizerTests/rematerialiser/do_not_remat_large_amounts_of_code1.yul)2
-rw-r--r--test/libyul/yulOptimizerTests/rematerialiser/expression.yul10
-rw-r--r--test/libyul/yulOptimizerTests/rematerialiser/large_constant.yul12
-rw-r--r--test/libyul/yulOptimizerTests/rematerialiser/large_constant_used_once.yul13
-rw-r--r--test/libyul/yulOptimizerTests/rematerialiser/medium_sized_constant.yul25
-rw-r--r--test/tools/yulopti.cpp2
22 files changed, 211 insertions, 167 deletions
diff --git a/test/cmdlineTests.sh b/test/cmdlineTests.sh
index bdd60863..00cc3633 100755
--- a/test/cmdlineTests.sh
+++ b/test/cmdlineTests.sh
@@ -100,17 +100,19 @@ printTask "Testing unknown options..."
failed=$?
set -e
- if [ "$output" == "unrecognised option '--allow=test'" ] && [ $failed -ne 0 ] ; then
- echo "Passed"
+ if [ "$output" == "unrecognised option '--allow=test'" ] && [ $failed -ne 0 ]
+ then
+ echo "Passed"
else
- printError "Incorrect response to unknown options: $STDERR"
- exit 1
+ printError "Incorrect response to unknown options: $STDERR"
+ exit 1
fi
)
# General helper function for testing SOLC behaviour, based on file name, compile opts, exit code, stdout and stderr.
# An failure is expected.
-test_solc_behaviour() {
+function test_solc_behaviour()
+{
local filename="${1}"
local solc_args="${2}"
local solc_stdin="${3}"
@@ -122,7 +124,8 @@ test_solc_behaviour() {
if [[ "$exit_code_expected" = "" ]]; then exit_code_expected="0"; fi
set +e
- if [[ "$solc_stdin" = "" ]]; then
+ if [[ "$solc_stdin" = "" ]]
+ then
"$SOLC" "${filename}" ${solc_args} 1>$stdout_path 2>$stderr_path
else
"$SOLC" "${filename}" ${solc_args} <$solc_stdin 1>$stdout_path 2>$stderr_path
@@ -130,7 +133,8 @@ test_solc_behaviour() {
exitCode=$?
set -e
- if [[ "$solc_args" == *"--standard-json"* ]]; then
+ if [[ "$solc_args" == *"--standard-json"* ]]
+ then
sed -i -e 's/{[^{]*Warning: This is a pre-release compiler version[^}]*},\{0,1\}//' "$stdout_path"
sed -i -e 's/"errors":\[\],\{0,1\}//' "$stdout_path"
else
@@ -138,13 +142,15 @@ test_solc_behaviour() {
sed -i -e 's/ Consider adding "pragma .*$//' "$stderr_path"
fi
- if [[ $exitCode -ne "$exit_code_expected" ]]; then
+ if [[ $exitCode -ne "$exit_code_expected" ]]
+ then
printError "Incorrect exit code. Expected $exit_code_expected but got $exitCode."
rm -f $stdout_path $stderr_path
exit 1
fi
- if [[ "$(cat $stdout_path)" != "${stdout_expected}" ]]; then
+ if [[ "$(cat $stdout_path)" != "${stdout_expected}" ]]
+ then
printError "Incorrect output on stdout received. Expected:"
echo -e "${stdout_expected}"
@@ -156,7 +162,8 @@ test_solc_behaviour() {
exit 1
fi
- if [[ "$(cat $stderr_path)" != "${stderr_expected}" ]]; then
+ if [[ "$(cat $stderr_path)" != "${stderr_expected}" ]]
+ then
printError "Incorrect output on stderr received. Expected:"
echo -e "${stderr_expected}"
@@ -183,46 +190,43 @@ test_solc_behaviour "${0}" "ctx:=/some/remapping/target" "" "" 1 "Invalid remapp
printTask "Running standard JSON commandline tests..."
(
-cd "$REPO_ROOT"/test/cmdlineTests/
-for file in *.json
-do
- args="--standard-json"
- stdin="$REPO_ROOT/test/cmdlineTests/$file"
- stdout=$(cat $file.stdout 2>/dev/null || true)
- exitCode=$(cat $file.exit 2>/dev/null || true)
- err=$(cat $file.err 2>/dev/null || true)
- printTask " - $file"
- test_solc_behaviour "" "$args" "$stdin" "$stdout" "$exitCode" "$err"
-done
+ cd "$REPO_ROOT"/test/cmdlineTests/
+ for file in *.json
+ do
+ args="--standard-json"
+ stdin="$REPO_ROOT/test/cmdlineTests/$file"
+ stdout=$(cat $file.stdout 2>/dev/null || true)
+ exitCode=$(cat $file.exit 2>/dev/null || true)
+ err=$(cat $file.err 2>/dev/null || true)
+ printTask " - $file"
+ test_solc_behaviour "" "$args" "$stdin" "$stdout" "$exitCode" "$err"
+ done
)
printTask "Running general commandline tests..."
(
-cd "$REPO_ROOT"/test/cmdlineTests/
-for file in *.sol
-do
- args=$(cat $file.args 2>/dev/null || true)
- stdout=$(cat $file.stdout 2>/dev/null || true)
- exitCode=$(cat $file.exit 2>/dev/null || true)
- err=$(cat $file.err 2>/dev/null || true)
- printTask " - $file"
- test_solc_behaviour "$file" "$args" "" "$stdout" "$exitCode" "$err"
-done
+ cd "$REPO_ROOT"/test/cmdlineTests/
+ for file in *.sol
+ do
+ args=$(cat $file.args 2>/dev/null || true)
+ stdout=$(cat $file.stdout 2>/dev/null || true)
+ exitCode=$(cat $file.exit 2>/dev/null || true)
+ err=$(cat $file.err 2>/dev/null || true)
+ printTask " - $file"
+ test_solc_behaviour "$file" "$args" "" "$stdout" "$exitCode" "$err"
+ done
)
printTask "Compiling various other contracts and libraries..."
(
-cd "$REPO_ROOT"/test/compilationTests/
-for dir in *
-do
- if [ "$dir" != "README.md" ]
- then
+ cd "$REPO_ROOT"/test/compilationTests/
+ for dir in */
+ do
echo " - $dir"
cd "$dir"
compileFull -w *.sol */*.sol
cd ..
- fi
-done
+ done
)
printTask "Compiling all examples from the documentation..."
@@ -297,7 +301,8 @@ SOLTMPDIR=$(mktemp -d)
)
rm -rf "$SOLTMPDIR"
-test_solc_assembly_output() {
+function test_solc_assembly_output()
+{
local input="${1}"
local expected="${2}"
local solc_args="${3}"
@@ -346,7 +351,8 @@ SOLTMPDIR=$(mktemp -d)
set -e
# This should fail
- if [[ !("$output" =~ "No input files given") || ($result == 0) ]] ; then
+ if [[ !("$output" =~ "No input files given") || ($result == 0) ]]
+ then
printError "Incorrect response to empty input arg list: $STDERR"
exit 1
fi
@@ -357,7 +363,8 @@ SOLTMPDIR=$(mktemp -d)
set -e
# The contract should be compiled
- if [[ "$result" != 0 ]] ; then
+ if [[ "$result" != 0 ]]
+ then
exit 1
fi
@@ -365,7 +372,8 @@ SOLTMPDIR=$(mktemp -d)
set +e
output=$(echo '' | "$SOLC" --ast - 2>/dev/null)
set -e
- if [[ $? != 0 ]] ; then
+ if [[ $? != 0 ]]
+ then
exit 1
fi
)
@@ -383,14 +391,16 @@ SOLTMPDIR=$(mktemp -d)
do
set +e
"$REPO_ROOT"/build/test/tools/solfuzzer --quiet < "$f"
- if [ $? -ne 0 ]; then
+ if [ $? -ne 0 ]
+ then
printError "Fuzzer failed on:"
cat "$f"
exit 1
fi
"$REPO_ROOT"/build/test/tools/solfuzzer --without-optimizer --quiet < "$f"
- if [ $? -ne 0 ]; then
+ if [ $? -ne 0 ]
+ then
printError "Fuzzer (without optimizer) failed on:"
cat "$f"
exit 1
diff --git a/test/cmdlineTests/too_long_line_multiline.sol b/test/cmdlineTests/too_long_line_multiline.sol
new file mode 100644
index 00000000..6609e125
--- /dev/null
+++ b/test/cmdlineTests/too_long_line_multiline.sol
@@ -0,0 +1,13 @@
+contract C {
+ function f() returns (byte _b, bytes2 _b2, bytes3 _b3, bytes memory _blit, bytes5 _b5, bytes6 _b6, string memory _str, bytes7 _b7, bytes22 _b22, bytes32 _b32) {
+ _b = 0x12;
+ _b2 = 0x1223;
+ _b5 = hex"043245";
+ _b6 = hex"2345532532";
+ _b7 = hex"03252353253253";
+ _b22 = hex"325235235325325325235325";
+ _b32 = hex"032523532532523532523532523532";
+ _blit = hex"123498";
+ _str = "heidy";
+ }
+}
diff --git a/test/cmdlineTests/too_long_line_multiline.sol.err b/test/cmdlineTests/too_long_line_multiline.sol.err
new file mode 100644
index 00000000..d7412ffe
--- /dev/null
+++ b/test/cmdlineTests/too_long_line_multiline.sol.err
@@ -0,0 +1,6 @@
+too_long_line_multiline.sol:2:5: Error: No visibility specified. Did you intend to add "public"?
+ function f() returns (byte _b, byte ... _b7, bytes22 _b22, bytes32 _b32) {
+ ^ (Relevant source part starts here and spans across multiple lines).
+too_long_line_multiline.sol:1:1: Warning: Source file does not specify required compiler version!
+contract C {
+^ (Relevant source part starts here and spans across multiple lines).
diff --git a/test/cmdlineTests/too_long_line_multiline.sol.exit b/test/cmdlineTests/too_long_line_multiline.sol.exit
new file mode 100644
index 00000000..d00491fd
--- /dev/null
+++ b/test/cmdlineTests/too_long_line_multiline.sol.exit
@@ -0,0 +1 @@
+1
diff --git a/test/libyul/YulOptimizerTest.cpp b/test/libyul/YulOptimizerTest.cpp
index 9643a1e9..0c782b17 100644
--- a/test/libyul/YulOptimizerTest.cpp
+++ b/test/libyul/YulOptimizerTest.cpp
@@ -171,7 +171,7 @@ bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool con
else if (m_optimizerStep == "rematerialiser")
{
disambiguate();
- (Rematerialiser{})(*m_ast);
+ Rematerialiser::run(*m_ast);
}
else if (m_optimizerStep == "expressionSimplifier")
{
diff --git a/test/libyul/objectCompiler/nested_optimizer.yul b/test/libyul/objectCompiler/nested_optimizer.yul
index 7739ce61..2775c346 100644
--- a/test/libyul/objectCompiler/nested_optimizer.yul
+++ b/test/libyul/objectCompiler/nested_optimizer.yul
@@ -19,31 +19,21 @@ object "a" {
// Assembly:
// /* "source":60:61 */
// 0x00
-// /* "source":137:138 */
-// dup1
-// /* "source":60:61 */
-// dup2
+// 0x00
// /* "source":47:62 */
// calldataload
// /* "source":119:139 */
// sstore
-// /* "source":32:143 */
-// pop
// stop
//
// sub_0: assembly {
// /* "source":200:201 */
// 0x00
-// /* "source":283:284 */
-// dup1
-// /* "source":200:201 */
-// dup2
+// 0x00
// /* "source":187:202 */
// calldataload
// /* "source":265:285 */
// sstore
-// /* "source":170:291 */
-// pop
// }
-// Bytecode: 60008081355550fe
-// Opcodes: PUSH1 0x0 DUP1 DUP2 CALLDATALOAD SSTORE POP INVALID
+// Bytecode: 600060003555fe
+// Opcodes: PUSH1 0x0 PUSH1 0x0 CALLDATALOAD SSTORE INVALID
diff --git a/test/libyul/objectCompiler/simple_optimizer.yul b/test/libyul/objectCompiler/simple_optimizer.yul
index 43b33553..c757dee7 100644
--- a/test/libyul/objectCompiler/simple_optimizer.yul
+++ b/test/libyul/objectCompiler/simple_optimizer.yul
@@ -9,15 +9,10 @@
// Assembly:
// /* "source":38:39 */
// 0x00
-// /* "source":109:110 */
-// dup1
-// /* "source":38:39 */
-// dup2
+// 0x00
// /* "source":25:40 */
// calldataload
// /* "source":91:111 */
// sstore
-// /* "source":12:113 */
-// pop
-// Bytecode: 60008081355550
-// Opcodes: PUSH1 0x0 DUP1 DUP2 CALLDATALOAD SSTORE POP
+// Bytecode: 600060003555
+// Opcodes: PUSH1 0x0 PUSH1 0x0 CALLDATALOAD SSTORE
diff --git a/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul b/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul
index efb846f2..b261b5bc 100644
--- a/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul
+++ b/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul
@@ -460,14 +460,13 @@
// {
// {
// let _1 := 0x20
-// let _2 := 0
-// let _485 := mload(_2)
+// let _485 := mload(0)
// let abi_encode_pos := _1
// let abi_encode_length_68 := mload(_485)
// mstore(_1, abi_encode_length_68)
// abi_encode_pos := 64
// let abi_encode_srcPtr := add(_485, _1)
-// let abi_encode_i_69 := _2
+// let abi_encode_i_69 := 0
// for {
// }
// lt(abi_encode_i_69, abi_encode_length_68)
@@ -477,12 +476,11 @@
// {
// let _863 := mload(abi_encode_srcPtr)
// let abi_encode_pos_71_971 := abi_encode_pos
-// let abi_encode_length_72_972 := 0x3
// let abi_encode_srcPtr_73_973 := _863
-// let abi_encode_i_74_974 := _2
+// let abi_encode_i_74_974 := 0
// for {
// }
-// lt(abi_encode_i_74_974, abi_encode_length_72_972)
+// lt(abi_encode_i_74_974, 0x3)
// {
// abi_encode_i_74_974 := add(abi_encode_i_74_974, 1)
// }
@@ -497,28 +495,24 @@
// let a, b, c, d := abi_decode_tuple_t_uint256t_uint256t_array$_t_uint256_$dyn_memory_ptrt_array$_t_array$_t_uint256_$2_memory_$dyn_memory_ptr(mload(_1), mload(0x40))
// sstore(a, b)
// sstore(c, d)
-// sstore(_2, abi_encode_pos)
+// sstore(0, abi_encode_pos)
// }
// function abi_decode_t_array$_t_array$_t_uint256_$2_memory_$dyn_memory_ptr(offset_3, end_4) -> array_5
// {
// if iszero(slt(add(offset_3, 0x1f), end_4))
// {
-// revert(array_5, array_5)
+// revert(0, 0)
// }
// let length_6 := calldataload(offset_3)
// let array_5_254 := allocateMemory(array_allocation_size_t_array$_t_array$_t_uint256_$2_memory_$dyn_memory_ptr(length_6))
// array_5 := array_5_254
// let dst_7 := array_5_254
// mstore(array_5_254, length_6)
-// let _36 := 0x20
-// let offset_3_256 := add(offset_3, _36)
-// dst_7 := add(array_5_254, _36)
-// let src_8 := offset_3_256
-// let _38 := 0x40
-// if gt(add(add(offset_3, mul(length_6, _38)), _36), end_4)
+// dst_7 := add(array_5_254, 0x20)
+// let src_8 := add(offset_3, 0x20)
+// if gt(add(add(offset_3, mul(length_6, 0x40)), 0x20), end_4)
// {
-// let _42 := 0
-// revert(_42, _42)
+// revert(0, 0)
// }
// let i_9 := 0
// for {
@@ -529,46 +523,42 @@
// }
// {
// mstore(dst_7, abi_decode_t_array$_t_uint256_$2_memory(src_8, end_4))
-// dst_7 := add(dst_7, _36)
-// src_8 := add(src_8, _38)
+// dst_7 := add(dst_7, 0x20)
+// src_8 := add(src_8, 0x40)
// }
// }
// function abi_decode_t_array$_t_uint256_$2_memory(offset_11, end_12) -> array_13
// {
// if iszero(slt(add(offset_11, 0x1f), end_12))
// {
-// revert(array_13, array_13)
+// revert(0, 0)
// }
-// let length_14 := 0x2
-// let array_allo__559 := 0x20
-// let array_allo_size_95_605 := 64
-// let array_13_263 := allocateMemory(array_allo_size_95_605)
+// let array_13_263 := allocateMemory(64)
// array_13 := array_13_263
// let dst_15 := array_13_263
// let src_16 := offset_11
-// if gt(add(offset_11, array_allo_size_95_605), end_12)
+// if gt(add(offset_11, 64), end_12)
// {
-// let _59 := 0
-// revert(_59, _59)
+// revert(0, 0)
// }
// let i_17 := 0
// for {
// }
-// lt(i_17, length_14)
+// lt(i_17, 0x2)
// {
// i_17 := add(i_17, 1)
// }
// {
// mstore(dst_15, calldataload(src_16))
-// dst_15 := add(dst_15, array_allo__559)
-// src_16 := add(src_16, array_allo__559)
+// dst_15 := add(dst_15, 0x20)
+// src_16 := add(src_16, 0x20)
// }
// }
// function abi_decode_t_array$_t_uint256_$dyn_memory_ptr(offset_27, end_28) -> array_29
// {
// if iszero(slt(add(offset_27, 0x1f), end_28))
// {
-// revert(array_29, array_29)
+// revert(0, 0)
// }
// let length_30 := calldataload(offset_27)
// let array_29_279 := allocateMemory(array_allocation_size_t_array$_t_uint256_$dyn_memory_ptr(length_30))
@@ -576,13 +566,11 @@
// let dst_31 := array_29_279
// mstore(array_29_279, length_30)
// let _91 := 0x20
-// let offset_27_281 := add(offset_27, _91)
// dst_31 := add(array_29_279, _91)
-// let src_32 := offset_27_281
+// let src_32 := add(offset_27, _91)
// if gt(add(add(offset_27, mul(length_30, _91)), _91), end_28)
// {
-// let _97 := 0
-// revert(_97, _97)
+// revert(0, 0)
// }
// let i_33 := 0
// for {
@@ -621,40 +609,36 @@
// let offset_65 := calldataload(add(headStart_58, 96))
// if gt(offset_65, 0xffffffffffffffff)
// {
-// revert(value3, value3)
+// revert(0, 0)
// }
// value3 := abi_decode_t_array$_t_array$_t_uint256_$2_memory_$dyn_memory_ptr(add(headStart_58, offset_65), dataEnd_59)
// }
// }
// function allocateMemory(size) -> memPtr
// {
-// let _199 := 64
-// let memPtr_315 := mload(_199)
+// let memPtr_315 := mload(64)
// memPtr := memPtr_315
// let newFreePtr := add(memPtr_315, size)
// if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr_315))
// {
-// let _204 := 0
-// revert(_204, _204)
+// revert(0, 0)
// }
-// mstore(_199, newFreePtr)
+// mstore(64, newFreePtr)
// }
// function array_allocation_size_t_array$_t_array$_t_uint256_$2_memory_$dyn_memory_ptr(length_92) -> size_93
// {
// if gt(length_92, 0xffffffffffffffff)
// {
-// revert(size_93, size_93)
+// revert(0, 0)
// }
-// let _217 := 0x20
-// size_93 := add(mul(length_92, _217), _217)
+// size_93 := add(mul(length_92, 0x20), 0x20)
// }
// function array_allocation_size_t_array$_t_uint256_$dyn_memory_ptr(length_98) -> size_99
// {
// if gt(length_98, 0xffffffffffffffff)
// {
-// revert(size_99, size_99)
+// revert(0, 0)
// }
-// let _234 := 0x20
-// size_99 := add(mul(length_98, _234), _234)
+// size_99 := add(mul(length_98, 0x20), 0x20)
// }
// }
diff --git a/test/libyul/yulOptimizerTests/fullSuite/medium.yul b/test/libyul/yulOptimizerTests/fullSuite/medium.yul
index fbe243d4..5578452a 100644
--- a/test/libyul/yulOptimizerTests/fullSuite/medium.yul
+++ b/test/libyul/yulOptimizerTests/fullSuite/medium.yul
@@ -20,12 +20,11 @@
// fullSuite
// {
// {
-// let _1 := 0x20
// let allocate__19 := 0x40
-// mstore(allocate__19, add(mload(allocate__19), _1))
+// mstore(allocate__19, add(mload(allocate__19), 0x20))
// let allocate_p_24_41 := mload(allocate__19)
// mstore(allocate__19, add(allocate_p_24_41, allocate__19))
// mstore(add(allocate_p_24_41, 96), 2)
-// mstore(allocate__19, _1)
+// mstore(allocate__19, 0x20)
// }
// }
diff --git a/test/libyul/yulOptimizerTests/rematerialiser/branches_for1.yul b/test/libyul/yulOptimizerTests/rematerialiser/branches_for1.yul
index dbd1ee63..3160381f 100644
--- a/test/libyul/yulOptimizerTests/rematerialiser/branches_for1.yul
+++ b/test/libyul/yulOptimizerTests/rematerialiser/branches_for1.yul
@@ -1,5 +1,5 @@
{
- let a := 1
+ let a := caller()
for { pop(a) } a { pop(a) } {
pop(a)
}
@@ -7,15 +7,15 @@
// ----
// rematerialiser
// {
-// let a := 1
+// let a := caller()
// for {
-// pop(1)
+// pop(caller())
// }
-// 1
+// caller()
// {
-// pop(1)
+// pop(caller())
// }
// {
-// pop(1)
+// pop(caller())
// }
// }
diff --git a/test/libyul/yulOptimizerTests/rematerialiser/branches_for2.yul b/test/libyul/yulOptimizerTests/rematerialiser/branches_for2.yul
index 6a52e045..eb092e95 100644
--- a/test/libyul/yulOptimizerTests/rematerialiser/branches_for2.yul
+++ b/test/libyul/yulOptimizerTests/rematerialiser/branches_for2.yul
@@ -1,7 +1,7 @@
{
- let a := 1
+ let a := caller()
for { pop(a) } a { pop(a) } {
- a := 7
+ a := address()
let c := a
}
let x := a
@@ -9,17 +9,17 @@
// ----
// rematerialiser
// {
-// let a := 1
+// let a := caller()
// for {
-// pop(1)
+// pop(caller())
// }
// a
// {
-// pop(7)
+// pop(address())
// }
// {
-// a := 7
-// let c := 7
+// a := address()
+// let c := address()
// }
// let x := a
// }
diff --git a/test/libyul/yulOptimizerTests/rematerialiser/branches_for_declared_in_init1.yul b/test/libyul/yulOptimizerTests/rematerialiser/branches_for_declared_in_init1.yul
index fc816419..e7c689ca 100644
--- a/test/libyul/yulOptimizerTests/rematerialiser/branches_for_declared_in_init1.yul
+++ b/test/libyul/yulOptimizerTests/rematerialiser/branches_for_declared_in_init1.yul
@@ -1,6 +1,6 @@
{
let b := 0
- for { let a := 1 pop(a) } a { pop(a) } {
+ for { let a := caller() pop(a) } a { pop(a) } {
b := 1 pop(a)
}
}
@@ -9,15 +9,15 @@
// {
// let b := 0
// for {
-// let a := 1
-// pop(1)
+// let a := caller()
+// pop(caller())
// }
-// 1
+// caller()
// {
-// pop(1)
+// pop(caller())
// }
// {
// b := 1
-// pop(1)
+// pop(caller())
// }
// }
diff --git a/test/libyul/yulOptimizerTests/rematerialiser/branches_for_declared_in_init2.yul b/test/libyul/yulOptimizerTests/rematerialiser/branches_for_declared_in_init2.yul
index 3d916890..80ee9233 100644
--- a/test/libyul/yulOptimizerTests/rematerialiser/branches_for_declared_in_init2.yul
+++ b/test/libyul/yulOptimizerTests/rematerialiser/branches_for_declared_in_init2.yul
@@ -1,6 +1,6 @@
{
let b := 0
- for { let a := 1 pop(a) } lt(a, 0) { pop(a) a := add(a, 3) } {
+ for { let a := caller() pop(a) } lt(a, 0) { pop(a) a := add(a, 3) } {
b := 1 pop(a)
}
}
@@ -9,8 +9,8 @@
// {
// let b := 0
// for {
-// let a := 1
-// pop(1)
+// let a := caller()
+// pop(caller())
// }
// lt(a, 0)
// {
diff --git a/test/libyul/yulOptimizerTests/rematerialiser/branches_if.yul b/test/libyul/yulOptimizerTests/rematerialiser/branches_if.yul
index c148c2f2..2aff06d4 100644
--- a/test/libyul/yulOptimizerTests/rematerialiser/branches_if.yul
+++ b/test/libyul/yulOptimizerTests/rematerialiser/branches_if.yul
@@ -1,18 +1,18 @@
{
- let a := 1
- let b := 2
+ let a := caller()
+ let b := address()
if b { pop(b) b := a }
let c := b
}
// ----
// rematerialiser
// {
-// let a := 1
-// let b := 2
-// if 2
+// let a := caller()
+// let b := address()
+// if address()
// {
-// pop(2)
-// b := 1
+// pop(address())
+// b := caller()
// }
// let c := b
// }
diff --git a/test/libyul/yulOptimizerTests/rematerialiser/cheap_caller.yul b/test/libyul/yulOptimizerTests/rematerialiser/cheap_caller.yul
new file mode 100644
index 00000000..7e99e428
--- /dev/null
+++ b/test/libyul/yulOptimizerTests/rematerialiser/cheap_caller.yul
@@ -0,0 +1,16 @@
+{
+ // The caller opcode is cheap, so inline it,
+ // no matter how often it is used
+ let a := caller()
+ mstore(a, a)
+ mstore(add(a, a), mload(a))
+ sstore(a, sload(a))
+}
+// ----
+// rematerialiser
+// {
+// let a := caller()
+// mstore(caller(), caller())
+// mstore(add(caller(), caller()), mload(caller()))
+// sstore(caller(), sload(caller()))
+// }
diff --git a/test/libyul/yulOptimizerTests/rematerialiser/do_not_remat_large_amounts_of_code2.yul b/test/libyul/yulOptimizerTests/rematerialiser/do_not_remat_large_amounts_of_code2.yul
deleted file mode 100644
index d95dc1fc..00000000
--- a/test/libyul/yulOptimizerTests/rematerialiser/do_not_remat_large_amounts_of_code2.yul
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- let x := add(mul(calldataload(2), calldataload(4)), calldatasize())
- let b := x
-}
-// ----
-// rematerialiser
-// {
-// let x := add(mul(calldataload(2), calldataload(4)), calldatasize())
-// let b := add(mul(calldataload(2), calldataload(4)), calldatasize())
-// }
diff --git a/test/libyul/yulOptimizerTests/rematerialiser/do_not_remat_large_amounts_of_code1.yul b/test/libyul/yulOptimizerTests/rematerialiser/do_remat_large_amounts_of_code_if_used_once.yul
index 016fa0d7..e464d404 100644
--- a/test/libyul/yulOptimizerTests/rematerialiser/do_not_remat_large_amounts_of_code1.yul
+++ b/test/libyul/yulOptimizerTests/rematerialiser/do_remat_large_amounts_of_code_if_used_once.yul
@@ -6,5 +6,5 @@
// rematerialiser
// {
// let x := add(mul(calldataload(2), calldataload(4)), mul(2, calldatasize()))
-// let b := x
+// let b := add(mul(calldataload(2), calldataload(4)), mul(2, calldatasize()))
// }
diff --git a/test/libyul/yulOptimizerTests/rematerialiser/expression.yul b/test/libyul/yulOptimizerTests/rematerialiser/expression.yul
deleted file mode 100644
index a801677d..00000000
--- a/test/libyul/yulOptimizerTests/rematerialiser/expression.yul
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- let a := add(mul(calldatasize(), 2), number())
- let b := add(a, a)
-}
-// ----
-// rematerialiser
-// {
-// let a := add(mul(calldatasize(), 2), number())
-// let b := add(add(mul(calldatasize(), 2), number()), add(mul(calldatasize(), 2), number()))
-// }
diff --git a/test/libyul/yulOptimizerTests/rematerialiser/large_constant.yul b/test/libyul/yulOptimizerTests/rematerialiser/large_constant.yul
new file mode 100644
index 00000000..9c7c66f1
--- /dev/null
+++ b/test/libyul/yulOptimizerTests/rematerialiser/large_constant.yul
@@ -0,0 +1,12 @@
+{
+ // Constants cost depending on their magnitude.
+ // Do not rematerialize large constants.
+ let a := 0xffffffffffffffffffffff
+ mstore(a, a)
+}
+// ----
+// rematerialiser
+// {
+// let a := 0xffffffffffffffffffffff
+// mstore(a, a)
+// }
diff --git a/test/libyul/yulOptimizerTests/rematerialiser/large_constant_used_once.yul b/test/libyul/yulOptimizerTests/rematerialiser/large_constant_used_once.yul
new file mode 100644
index 00000000..b8a861aa
--- /dev/null
+++ b/test/libyul/yulOptimizerTests/rematerialiser/large_constant_used_once.yul
@@ -0,0 +1,13 @@
+{
+ // Constants cost depending on their magnitude.
+ // Do not rematerialize large constants,
+ // unless they are used exactly once.
+ let a := 0xffffffffffffffffffffff
+ mstore(0, a)
+}
+// ----
+// rematerialiser
+// {
+// let a := 0xffffffffffffffffffffff
+// mstore(0, 0xffffffffffffffffffffff)
+// }
diff --git a/test/libyul/yulOptimizerTests/rematerialiser/medium_sized_constant.yul b/test/libyul/yulOptimizerTests/rematerialiser/medium_sized_constant.yul
new file mode 100644
index 00000000..98cdbd09
--- /dev/null
+++ b/test/libyul/yulOptimizerTests/rematerialiser/medium_sized_constant.yul
@@ -0,0 +1,25 @@
+{
+ // Constants cost depending on their magnitude.
+ // Rematerialize small constants only if they are
+ // not used too often.
+ // b is used 5 times
+ let b := 2
+ mstore(b, b)
+ mstore(add(b, b), b)
+ // a is used 7 times
+ let a := 1
+ mstore(a, a)
+ mstore(add(a, a), a)
+ mstore(a, mload(a))
+}
+// ----
+// rematerialiser
+// {
+// let b := 2
+// mstore(2, 2)
+// mstore(add(2, 2), 2)
+// let a := 1
+// mstore(a, a)
+// mstore(add(a, a), a)
+// mstore(a, mload(a))
+// }
diff --git a/test/tools/yulopti.cpp b/test/tools/yulopti.cpp
index fcbe308f..e88b0538 100644
--- a/test/tools/yulopti.cpp
+++ b/test/tools/yulopti.cpp
@@ -182,7 +182,7 @@ public:
RedundantAssignEliminator::run(*m_ast);
break;
case 'm':
- Rematerialiser{}(*m_ast);
+ Rematerialiser::run(*m_ast);
break;
default:
cout << "Unknown option." << endl;