diff --git a/libsolidity/codegen/ir/IRGenerator.cpp b/libsolidity/codegen/ir/IRGenerator.cpp index 4837b3ff2..a1d1522a6 100644 --- a/libsolidity/codegen/ir/IRGenerator.cpp +++ b/libsolidity/codegen/ir/IRGenerator.cpp @@ -802,29 +802,24 @@ void IRGenerator::generateImplicitConstructors(ContractDefinition const& _contra string IRGenerator::deployCode(ContractDefinition const& _contract) { Whiskers t(R"X( - <#loadImmutables> - let := mload() - - - codecopy(0, dataoffset(""), datasize("")) - - <#storeImmutables> - setimmutable(0, "", ) - - - return(0, datasize("")) + let := () + codecopy(, dataoffset(""), datasize("")) + <#immutables> + setimmutable(, "", ) + + return(, datasize("")) )X"); + t("allocateUnbounded", m_utils.allocateUnboundedFunction()); + t("codeOffset", m_context.newYulVariable()); t("object", IRNames::deployedObject(_contract)); - vector> loadImmutables; - vector> storeImmutables; - + vector> immutables; if (_contract.isLibrary()) { solAssert(ContractType(_contract).immutableVariables().empty(), ""); - storeImmutables.emplace_back(map{ - {"var"s, "address()"}, - {"immutableName"s, IRNames::libraryAddressImmutable()} + immutables.emplace_back(map{ + {"immutableName"s, IRNames::libraryAddressImmutable()}, + {"value"s, "address()"} }); } @@ -833,20 +828,12 @@ string IRGenerator::deployCode(ContractDefinition const& _contract) { solUnimplementedAssert(immutable->type()->isValueType(), ""); solUnimplementedAssert(immutable->type()->sizeOnStack() == 1, ""); - string yulVar = m_context.newYulVariable(); - loadImmutables.emplace_back(map{ - {"var"s, yulVar}, - {"memoryOffset"s, to_string(m_context.immutableMemoryOffset(*immutable))} - }); - storeImmutables.emplace_back(map{ - {"var"s, yulVar}, - {"immutableName"s, to_string(immutable->id())} + immutables.emplace_back(map{ + {"immutableName"s, to_string(immutable->id())}, + {"value"s, "mload(" + to_string(m_context.immutableMemoryOffset(*immutable)) + ")"} }); } - t("loadImmutables", std::move(loadImmutables)); - // reverse order to ease stack strain - reverse(storeImmutables.begin(), storeImmutables.end()); - t("storeImmutables", std::move(storeImmutables)); + t("immutables", std::move(immutables)); return t.render(); } diff --git a/test/cmdlineTests/constant_optimizer_yul/output b/test/cmdlineTests/constant_optimizer_yul/output index 9a125bd36..181a8105b 100644 --- a/test/cmdlineTests/constant_optimizer_yul/output +++ b/test/cmdlineTests/constant_optimizer_yul/output @@ -13,8 +13,8 @@ object "C_12" { if callvalue() { revert(0, 0) } sstore(0, shl(180, 1)) let _1 := datasize("C_12_deployed") - codecopy(0, dataoffset("C_12_deployed"), _1) - return(0, _1) + codecopy(128, dataoffset("C_12_deployed"), _1) + return(128, _1) } } object "C_12_deployed" { diff --git a/test/cmdlineTests/exp_base_literal/output b/test/cmdlineTests/exp_base_literal/output index d75851fd4..698180169 100644 --- a/test/cmdlineTests/exp_base_literal/output +++ b/test/cmdlineTests/exp_base_literal/output @@ -14,9 +14,14 @@ object "C_81" { constructor_C_81() - codecopy(0, dataoffset("C_81_deployed"), datasize("C_81_deployed")) + let _1 := allocate_unbounded() + codecopy(_1, dataoffset("C_81_deployed"), datasize("C_81_deployed")) - return(0, datasize("C_81_deployed")) + return(_1, datasize("C_81_deployed")) + + function allocate_unbounded() -> memPtr { + memPtr := mload(64) + } function constructor_C_81() { diff --git a/test/cmdlineTests/ir_compiler_inheritance_nosubobjects/output b/test/cmdlineTests/ir_compiler_inheritance_nosubobjects/output index 418676634..829981fcf 100644 --- a/test/cmdlineTests/ir_compiler_inheritance_nosubobjects/output +++ b/test/cmdlineTests/ir_compiler_inheritance_nosubobjects/output @@ -12,8 +12,8 @@ object "C_7" { mstore(64, 128) if callvalue() { revert(0, 0) } let _1 := datasize("C_7_deployed") - codecopy(0, dataoffset("C_7_deployed"), _1) - return(0, _1) + codecopy(128, dataoffset("C_7_deployed"), _1) + return(128, _1) } } object "C_7_deployed" { @@ -40,8 +40,8 @@ object "D_10" { mstore(64, 128) if callvalue() { revert(0, 0) } let _1 := datasize("D_10_deployed") - codecopy(0, dataoffset("D_10_deployed"), _1) - return(0, _1) + codecopy(128, dataoffset("D_10_deployed"), _1) + return(128, _1) } } object "D_10_deployed" { diff --git a/test/cmdlineTests/ir_compiler_subobjects/output b/test/cmdlineTests/ir_compiler_subobjects/output index 41a19e81c..96ebe2727 100644 --- a/test/cmdlineTests/ir_compiler_subobjects/output +++ b/test/cmdlineTests/ir_compiler_subobjects/output @@ -12,8 +12,8 @@ object "C_3" { mstore(64, 128) if callvalue() { revert(0, 0) } let _1 := datasize("C_3_deployed") - codecopy(0, dataoffset("C_3_deployed"), _1) - return(0, _1) + codecopy(128, dataoffset("C_3_deployed"), _1) + return(128, _1) } } object "C_3_deployed" { @@ -40,8 +40,8 @@ object "D_16" { mstore(64, 128) if callvalue() { revert(0, 0) } let _1 := datasize("D_16_deployed") - codecopy(0, dataoffset("D_16_deployed"), _1) - return(0, _1) + codecopy(128, dataoffset("D_16_deployed"), _1) + return(128, _1) } } object "D_16_deployed" { @@ -82,8 +82,8 @@ object "D_16" { mstore(64, 128) if callvalue() { revert(0, 0) } let _1 := datasize("C_3_deployed") - codecopy(0, dataoffset("C_3_deployed"), _1) - return(0, _1) + codecopy(128, dataoffset("C_3_deployed"), _1) + return(128, _1) } } object "C_3_deployed" { diff --git a/test/cmdlineTests/ir_with_assembly_no_memoryguard_creation/output b/test/cmdlineTests/ir_with_assembly_no_memoryguard_creation/output index ff7449119..72ed66a1d 100644 --- a/test/cmdlineTests/ir_with_assembly_no_memoryguard_creation/output +++ b/test/cmdlineTests/ir_with_assembly_no_memoryguard_creation/output @@ -12,8 +12,8 @@ object "D_12" { mstore(64, 128) if callvalue() { revert(0, 0) } let _1 := datasize("D_12_deployed") - codecopy(0, dataoffset("D_12_deployed"), _1) - return(0, _1) + codecopy(128, dataoffset("D_12_deployed"), _1) + return(128, _1) } } object "D_12_deployed" { diff --git a/test/cmdlineTests/ir_with_assembly_no_memoryguard_runtime/output b/test/cmdlineTests/ir_with_assembly_no_memoryguard_runtime/output index 2ed33af2e..a04c2f13b 100644 --- a/test/cmdlineTests/ir_with_assembly_no_memoryguard_runtime/output +++ b/test/cmdlineTests/ir_with_assembly_no_memoryguard_runtime/output @@ -12,8 +12,8 @@ object "D_8" { mstore(64, 128) if callvalue() { revert(0, 0) } let _1 := datasize("D_8_deployed") - codecopy(0, dataoffset("D_8_deployed"), _1) - return(0, _1) + codecopy(128, dataoffset("D_8_deployed"), _1) + return(128, _1) } } object "D_8_deployed" { diff --git a/test/cmdlineTests/keccak_optimization_deploy_code/output b/test/cmdlineTests/keccak_optimization_deploy_code/output index 5bdfaf647..48721502a 100644 --- a/test/cmdlineTests/keccak_optimization_deploy_code/output +++ b/test/cmdlineTests/keccak_optimization_deploy_code/output @@ -14,8 +14,8 @@ object "C_12" { mstore(0, 100) sstore(0, keccak256(0, 32)) let _1 := datasize("C_12_deployed") - codecopy(0, dataoffset("C_12_deployed"), _1) - return(0, _1) + codecopy(128, dataoffset("C_12_deployed"), _1) + return(128, _1) } } object "C_12_deployed" { diff --git a/test/cmdlineTests/keccak_optimization_low_runs/output b/test/cmdlineTests/keccak_optimization_low_runs/output index ab6027035..c2e9b023a 100644 --- a/test/cmdlineTests/keccak_optimization_low_runs/output +++ b/test/cmdlineTests/keccak_optimization_low_runs/output @@ -12,8 +12,8 @@ object "C_7" { mstore(64, 128) if callvalue() { revert(0, 0) } let _1 := datasize("C_7_deployed") - codecopy(0, dataoffset("C_7_deployed"), _1) - return(0, _1) + codecopy(128, dataoffset("C_7_deployed"), _1) + return(128, _1) } } object "C_7_deployed" { diff --git a/test/cmdlineTests/name_simplifier/output b/test/cmdlineTests/name_simplifier/output index 74c654798..526e5ce0f 100644 --- a/test/cmdlineTests/name_simplifier/output +++ b/test/cmdlineTests/name_simplifier/output @@ -12,8 +12,8 @@ object "C_59" { mstore(64, 128) if callvalue() { revert(0, 0) } let _1 := datasize("C_59_deployed") - codecopy(0, dataoffset("C_59_deployed"), _1) - return(0, _1) + codecopy(128, dataoffset("C_59_deployed"), _1) + return(128, _1) } } object "C_59_deployed" { diff --git a/test/cmdlineTests/optimizer_array_sload/output b/test/cmdlineTests/optimizer_array_sload/output index 0576e2890..f5a3cf77d 100644 --- a/test/cmdlineTests/optimizer_array_sload/output +++ b/test/cmdlineTests/optimizer_array_sload/output @@ -12,8 +12,8 @@ object "Arraysum_34" { mstore(64, 128) if callvalue() { revert(0, 0) } let _1 := datasize("Arraysum_34_deployed") - codecopy(0, dataoffset("Arraysum_34_deployed"), _1) - return(0, _1) + codecopy(128, dataoffset("Arraysum_34_deployed"), _1) + return(128, _1) } } object "Arraysum_34_deployed" { diff --git a/test/cmdlineTests/standard_ewasm_requested/output.json b/test/cmdlineTests/standard_ewasm_requested/output.json index aaa63db62..d3eef7f27 100644 --- a/test/cmdlineTests/standard_ewasm_requested/output.json +++ b/test/cmdlineTests/standard_ewasm_requested/output.json @@ -1,4 +1,4 @@ -{"contracts":{"A":{"C":{"ewasm":{"wasm":"0061736d010000000125086000006000017e6000017f60017e017f60017f0060017f017f60027f7f0060037f7f7f0002510408657468657265756d08636f6465436f7079000708657468657265756d06726576657274000608657468657265756d0c67657443616c6c56616c7565000408657468657265756d0666696e697368000603090800020302020505010503010001060100071102066d656d6f72790200046d61696e000400b6030c435f335f6465706c6f7965640061736d010000000112046000006000017f60017f017f60027f7f0002130108657468657265756d06726576657274000303060500010102020503010001060100071102066d656d6f72790200046d61696e00010ad20205a10104027f017e017f047e024010022100200041c0006a210120012000490440000b420021022002a7210320031005ad42208621042002422088210520042005a71005ad84210620012006370000200141086a2006370000200141106a2006370000428001a71005ad4220862107200141186a2007428001422088a71005ad8437000020022002200284200284520440000b20022005520440000b1003200310000b0b2b01017f024042004200420084420084520440000b420042c000422088520440000b42c000a721000b20000b4203017f017e017f02404200210120012001200184200184520440000b20012001422088520440000b2001a72102200241c0006a210020002002490440000b0b20000b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100441107421022002200041107610047221010b20010b0aa603089a0102027f047e024010072100200041c0006a210120012000490440000b4200a7100aad422086210220024200422088a7100aad84210320012003370000200141086a2003370000200141106a2003370000200141186a100b37000041001002410829000021044200420084200441002900008484504504401008100510010b42a9032105100842b801100620051006100010082005100610030b0b2f02017f017e02404200210120012001200184200184520440000b20012001422088520440000b2001a721000b20000b2901017f024042004200420084420084520440000b42002000422088520440000b2000a721010b20010b2b01017f024042004200420084420084520440000b420042c000422088520440000b42c000a721000b20000b1e01027f024010052101200141c0006a210020002001490440000b0b20000b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100941107421022002200041107610097221010b20010b2401027e0240428001a7100aad42208621012001428001422088a7100aad8421000b20000b","wast":"(module +{"contracts":{"A":{"C":{"ewasm":{"wasm":"0061736d010000000125086000006000017e6000017f60017e017f60017f0060017f017f60027f7f0060037f7f7f0002510408657468657265756d08636f6465436f7079000708657468657265756d06726576657274000608657468657265756d0c67657443616c6c56616c7565000408657468657265756d0666696e6973680006030a090002030202020505010503010001060100071102066d656d6f72790200046d61696e000400b6030c435f335f6465706c6f7965640061736d010000000112046000006000017f60017f017f60027f7f0002130108657468657265756d06726576657274000303060500010102020503010001060100071102066d656d6f72790200046d61696e00010ad20205a10104027f017e017f047e024010022100200041c0006a210120012000490440000b420021022002a7210320031005ad42208621042002422088210520042005a71005ad84210620012006370000200141086a2006370000200141106a2006370000428001a71005ad4220862107200141186a2007428001422088a71005ad8437000020022002200284200284520440000b20022005520440000b1003200310000b0b2b01017f024042004200420084420084520440000b420042c000422088520440000b42c000a721000b20000b4203017f017e017f02404200210120012001200184200184520440000b20012001422088520440000b2001a72102200241c0006a210020002002490440000b0b20000b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100441107421022002200041107610047221010b20010b0ae303099a0102027f047e024010072100200041c0006a210120012000490440000b4200a7100bad422086210220024200422088a7100bad84210320012003370000200141086a2003370000200141106a2003370000200141186a100c37000041001002410829000021044200420084200441002900008484504504401008100510010b42a9032105100942b901100620051006100010092005100610030b0b2f02017f017e02404200210120012001200184200184520440000b20012001422088520440000b2001a721000b20000b2901017f024042004200420084420084520440000b42002000422088520440000b2000a721010b20010b2b01017f024042004200420084420084520440000b420042c000422088520440000b42c000a721000b20000b1e01027f024010052101200141c0006a210020002001490440000b0b20000b3c01027f024042004200420084420084520440000b4200428001422088520440000b428001a72101200141c0006a210020002001490440000b0b20000b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100a411074210220022000411076100a7221010b20010b2401027e0240428001a7100bad42208621012001428001422088a7100bad8421000b20000b","wast":"(module ;; custom section for sub-module ;; The Keccak-256 hash of the text representation of \"C_3_deployed\": d5523336521d49fa8bd64dba28ece7291aa7d45c646a23eabd038bbeecc2d803 ;; (@custom \"C_3_deployed\" \"0061736d010000000112046000006000017f60017f017f60027f7f0002130108657468657265756d06726576657274000303060500010102020503010001060100071102066d656d6f72790200046d61696e00010ad20205a10104027f017e017f047e024010022100200041c0006a210120012000490440000b420021022002a7210320031005ad42208621042002422088210520042005a71005ad84210620012006370000200141086a2006370000200141106a2006370000428001a71005ad4220862107200141186a2007428001422088a71005ad8437000020022002200284200284520440000b20022005520440000b1003200310000b0b2b01017f024042004200420084420084520440000b420042c000422088520440000b42c000a721000b20000b4203017f017e017f02404200210120012001200184200184520440000b20012001422088520440000b2001a72102200241c0006a210020002002490440000b0b20000b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100441107421022002200041107610047221010b20010b\") @@ -32,8 +32,8 @@ (if (i32.eqz (i64.eqz (i64.or (i64.or (i64.const 0) (i64.const 0)) (i64.or (local.get $z3) (i64.load (i32.const 0)))))) (then (call $eth.revert (call $to_internal_i32ptr) (call $u256_to_i32_344)))) (local.set $_1 (datasize \"C_3_deployed\")) - (call $eth.codeCopy (call $to_internal_i32ptr) (call $u256_to_i32 (dataoffset \"C_3_deployed\")) (call $u256_to_i32 (local.get $_1))) - (call $eth.finish (call $to_internal_i32ptr) (call $u256_to_i32 (local.get $_1))) + (call $eth.codeCopy (call $to_internal_i32ptr_348) (call $u256_to_i32 (dataoffset \"C_3_deployed\")) (call $u256_to_i32 (local.get $_1))) + (call $eth.finish (call $to_internal_i32ptr_348) (call $u256_to_i32 (local.get $_1))) ) ) @@ -96,11 +96,29 @@ (local.get $r) ) +(func $to_internal_i32ptr_348 + (result i32) + (local $r i32) + (local $v i32) + (block $label__5 + (if (i64.ne (i64.const 0) (i64.or (i64.or (i64.const 0) (i64.const 0)) (i64.const 0))) (then + (unreachable))) + (if (i64.ne (i64.const 0) (i64.shr_u (i64.const 128) (i64.const 32))) (then + (unreachable))) + (local.set $v (i32.wrap_i64 (i64.const 128))) + (local.set $r (i32.add (local.get $v) (i32.const 64))) + (if (i32.lt_u (local.get $r) (local.get $v)) (then + (unreachable))) + + ) + (local.get $r) +) + (func $bswap16 (param $x i32) (result i32) (local $y i32) - (block $label__5 + (block $label__6 (local.set $y (i32.or (i32.and (i32.shl (local.get $x) (i32.const 8)) (i32.const 65280)) (i32.and (i32.shr_u (local.get $x) (i32.const 8)) (i32.const 255)))) ) @@ -112,7 +130,7 @@ (result i32) (local $y i32) (local $hi i32) - (block $label__6 + (block $label__7 (local.set $hi (i32.shl (call $bswap16 (local.get $x)) (i32.const 16))) (local.set $y (i32.or (local.get $hi) (call $bswap16 (i32.shr_u (local.get $x) (i32.const 16))))) @@ -124,7 +142,7 @@ (result i64) (local $y i64) (local $hi i64) - (block $label__7 + (block $label__8 (local.set $hi (i64.shl (i64.extend_i32_u (call $bswap32 (i32.wrap_i64 (i64.const 128)))) (i64.const 32))) (local.set $y (i64.or (local.get $hi) (i64.extend_i32_u (call $bswap32 (i32.wrap_i64 (i64.shr_u (i64.const 128) (i64.const 32))))))) diff --git a/test/cmdlineTests/standard_irOptimized_requested/output.json b/test/cmdlineTests/standard_irOptimized_requested/output.json index 0612727b2..2aeac9773 100644 --- a/test/cmdlineTests/standard_irOptimized_requested/output.json +++ b/test/cmdlineTests/standard_irOptimized_requested/output.json @@ -10,8 +10,11 @@ object \"C_7\" { mstore(64, 128) if callvalue() { revert(0, 0) } constructor_C_7() - codecopy(0, dataoffset(\"C_7_deployed\"), datasize(\"C_7_deployed\")) - return(0, datasize(\"C_7_deployed\")) + let _1 := allocate_unbounded() + codecopy(_1, dataoffset(\"C_7_deployed\"), datasize(\"C_7_deployed\")) + return(_1, datasize(\"C_7_deployed\")) + function allocate_unbounded() -> memPtr + { memPtr := mload(64) } function constructor_C_7() { } } diff --git a/test/cmdlineTests/standard_ir_requested/output.json b/test/cmdlineTests/standard_ir_requested/output.json index 567aa7efc..5b91fb56f 100644 --- a/test/cmdlineTests/standard_ir_requested/output.json +++ b/test/cmdlineTests/standard_ir_requested/output.json @@ -13,9 +13,14 @@ object \"C_7\" { constructor_C_7() - codecopy(0, dataoffset(\"C_7_deployed\"), datasize(\"C_7_deployed\")) + let _1 := allocate_unbounded() + codecopy(_1, dataoffset(\"C_7_deployed\"), datasize(\"C_7_deployed\")) - return(0, datasize(\"C_7_deployed\")) + return(_1, datasize(\"C_7_deployed\")) + + function allocate_unbounded() -> memPtr { + memPtr := mload(64) + } function constructor_C_7() { diff --git a/test/cmdlineTests/standard_viair_requested/output.json b/test/cmdlineTests/standard_viair_requested/output.json index 74c47d6a0..ca3054c46 100644 --- a/test/cmdlineTests/standard_viair_requested/output.json +++ b/test/cmdlineTests/standard_viair_requested/output.json @@ -13,9 +13,14 @@ object \"C_3\" { constructor_C_3() - codecopy(0, dataoffset(\"C_3_deployed\"), datasize(\"C_3_deployed\")) + let _1 := allocate_unbounded() + codecopy(_1, dataoffset(\"C_3_deployed\"), datasize(\"C_3_deployed\")) - return(0, datasize(\"C_3_deployed\")) + return(_1, datasize(\"C_3_deployed\")) + + function allocate_unbounded() -> memPtr { + memPtr := mload(64) + } function constructor_C_3() { @@ -64,9 +69,14 @@ object \"D_16\" { constructor_D_16() - codecopy(0, dataoffset(\"D_16_deployed\"), datasize(\"D_16_deployed\")) + let _1 := allocate_unbounded() + codecopy(_1, dataoffset(\"D_16_deployed\"), datasize(\"D_16_deployed\")) - return(0, datasize(\"D_16_deployed\")) + return(_1, datasize(\"D_16_deployed\")) + + function allocate_unbounded() -> memPtr { + memPtr := mload(64) + } function constructor_D_16() { @@ -163,9 +173,14 @@ object \"D_16\" { constructor_C_3() - codecopy(0, dataoffset(\"C_3_deployed\"), datasize(\"C_3_deployed\")) + let _1 := allocate_unbounded() + codecopy(_1, dataoffset(\"C_3_deployed\"), datasize(\"C_3_deployed\")) - return(0, datasize(\"C_3_deployed\")) + return(_1, datasize(\"C_3_deployed\")) + + function allocate_unbounded() -> memPtr { + memPtr := mload(64) + } function constructor_C_3() { diff --git a/test/cmdlineTests/viair_abicoder_v1/output b/test/cmdlineTests/viair_abicoder_v1/output index af0c29b36..37e957259 100644 --- a/test/cmdlineTests/viair_abicoder_v1/output +++ b/test/cmdlineTests/viair_abicoder_v1/output @@ -14,9 +14,14 @@ object "test_11" { constructor_test_11() - codecopy(0, dataoffset("test_11_deployed"), datasize("test_11_deployed")) + let _1 := allocate_unbounded() + codecopy(_1, dataoffset("test_11_deployed"), datasize("test_11_deployed")) - return(0, datasize("test_11_deployed")) + return(_1, datasize("test_11_deployed")) + + function allocate_unbounded() -> memPtr { + memPtr := mload(64) + } function constructor_test_11() { diff --git a/test/cmdlineTests/viair_subobjects/output b/test/cmdlineTests/viair_subobjects/output index e53814796..3847e7df6 100644 --- a/test/cmdlineTests/viair_subobjects/output +++ b/test/cmdlineTests/viair_subobjects/output @@ -1,7 +1,7 @@ ======= viair_subobjects/input.sol:C ======= Binary: -60806040523415600f5760006000fd5b600a80601e600039806000f350fe608060405260006000fd +60806040523415600f5760006000fd5b600a80601e608039806080f350fe608060405260006000fd Binary of the runtime part: 608060405260006000fd Optimized IR: @@ -18,8 +18,8 @@ object "C_3" { mstore(64, 128) if callvalue() { revert(0, 0) } let _1 := datasize("C_3_deployed") - codecopy(0, dataoffset("C_3_deployed"), _1) - return(0, _1) + codecopy(128, dataoffset("C_3_deployed"), _1) + return(128, _1) } } object "C_3_deployed" { @@ -35,9 +35,9 @@ object "C_3" { ======= viair_subobjects/input.sol:D ======= Binary: -608060405234156100105760006000fd5b60ba80610020600039806000f350fe6080604052600436101515608b576000803560e01c6326121ff0141560895734156027578081fd5b80600319360112156036578081fd5b6028806080016080811067ffffffffffffffff82111715606457634e487b7160e01b83526041600452602483fd5b508061009260803980608083f015156082576040513d83823e3d81fd505b5080604051f35b505b60006000fdfe60806040523415600f5760006000fd5b600a80601e600039806000f350fe608060405260006000fd +608060405234156100105760006000fd5b60ba80610020608039806080f350fe6080604052600436101515608b576000803560e01c6326121ff0141560895734156027578081fd5b80600319360112156036578081fd5b6028806080016080811067ffffffffffffffff82111715606457634e487b7160e01b83526041600452602483fd5b508061009260803980608083f015156082576040513d83823e3d81fd505b5080604051f35b505b60006000fdfe60806040523415600f5760006000fd5b600a80601e608039806080f350fe608060405260006000fd Binary of the runtime part: -6080604052600436101515608b576000803560e01c6326121ff0141560895734156027578081fd5b80600319360112156036578081fd5b6028806080016080811067ffffffffffffffff82111715606457634e487b7160e01b83526041600452602483fd5b508061009260803980608083f015156082576040513d83823e3d81fd505b5080604051f35b505b60006000fdfe60806040523415600f5760006000fd5b600a80601e600039806000f350fe608060405260006000fd +6080604052600436101515608b576000803560e01c6326121ff0141560895734156027578081fd5b80600319360112156036578081fd5b6028806080016080811067ffffffffffffffff82111715606457634e487b7160e01b83526041600452602483fd5b508061009260803980608083f015156082576040513d83823e3d81fd505b5080604051f35b505b60006000fdfe60806040523415600f5760006000fd5b600a80601e608039806080f350fe608060405260006000fd Optimized IR: /******************************************************* * WARNING * @@ -52,8 +52,8 @@ object "D_16" { mstore(64, 128) if callvalue() { revert(0, 0) } let _1 := datasize("D_16_deployed") - codecopy(0, dataoffset("D_16_deployed"), _1) - return(0, _1) + codecopy(128, dataoffset("D_16_deployed"), _1) + return(128, _1) } } object "D_16_deployed" { @@ -94,8 +94,8 @@ object "D_16" { mstore(64, 128) if callvalue() { revert(0, 0) } let _1 := datasize("C_3_deployed") - codecopy(0, dataoffset("C_3_deployed"), _1) - return(0, _1) + codecopy(128, dataoffset("C_3_deployed"), _1) + return(128, _1) } } object "C_3_deployed" { diff --git a/test/cmdlineTests/yul_optimizer_steps/output b/test/cmdlineTests/yul_optimizer_steps/output index aae106d4a..fe6a4be49 100644 --- a/test/cmdlineTests/yul_optimizer_steps/output +++ b/test/cmdlineTests/yul_optimizer_steps/output @@ -11,9 +11,12 @@ object "C_7" { { mstore(64, 128) if callvalue() { revert(0, 0) } - codecopy(0, dataoffset("C_7_deployed"), datasize("C_7_deployed")) - return(0, datasize("C_7_deployed")) + let _1 := allocate_unbounded() + codecopy(_1, dataoffset("C_7_deployed"), datasize("C_7_deployed")) + return(_1, datasize("C_7_deployed")) } + function allocate_unbounded() -> memPtr + { memPtr := mload(64) } } object "C_7_deployed" { code { diff --git a/test/cmdlineTests/yul_string_format_ascii/output.json b/test/cmdlineTests/yul_string_format_ascii/output.json index 012993def..28a63d8c3 100644 --- a/test/cmdlineTests/yul_string_format_ascii/output.json +++ b/test/cmdlineTests/yul_string_format_ascii/output.json @@ -13,9 +13,14 @@ object \"C_11\" { constructor_C_11() - codecopy(0, dataoffset(\"C_11_deployed\"), datasize(\"C_11_deployed\")) + let _1 := allocate_unbounded() + codecopy(_1, dataoffset(\"C_11_deployed\"), datasize(\"C_11_deployed\")) - return(0, datasize(\"C_11_deployed\")) + return(_1, datasize(\"C_11_deployed\")) + + function allocate_unbounded() -> memPtr { + memPtr := mload(64) + } function constructor_C_11() { diff --git a/test/cmdlineTests/yul_string_format_ascii_bytes32/output.json b/test/cmdlineTests/yul_string_format_ascii_bytes32/output.json index 5fb77fe75..eb6e8f48c 100644 --- a/test/cmdlineTests/yul_string_format_ascii_bytes32/output.json +++ b/test/cmdlineTests/yul_string_format_ascii_bytes32/output.json @@ -13,9 +13,14 @@ object \"C_11\" { constructor_C_11() - codecopy(0, dataoffset(\"C_11_deployed\"), datasize(\"C_11_deployed\")) + let _1 := allocate_unbounded() + codecopy(_1, dataoffset(\"C_11_deployed\"), datasize(\"C_11_deployed\")) - return(0, datasize(\"C_11_deployed\")) + return(_1, datasize(\"C_11_deployed\")) + + function allocate_unbounded() -> memPtr { + memPtr := mload(64) + } function constructor_C_11() { diff --git a/test/cmdlineTests/yul_string_format_ascii_bytes32_from_number/output.json b/test/cmdlineTests/yul_string_format_ascii_bytes32_from_number/output.json index a72e4db51..87d0f171c 100644 --- a/test/cmdlineTests/yul_string_format_ascii_bytes32_from_number/output.json +++ b/test/cmdlineTests/yul_string_format_ascii_bytes32_from_number/output.json @@ -13,9 +13,14 @@ object \"C_11\" { constructor_C_11() - codecopy(0, dataoffset(\"C_11_deployed\"), datasize(\"C_11_deployed\")) + let _1 := allocate_unbounded() + codecopy(_1, dataoffset(\"C_11_deployed\"), datasize(\"C_11_deployed\")) - return(0, datasize(\"C_11_deployed\")) + return(_1, datasize(\"C_11_deployed\")) + + function allocate_unbounded() -> memPtr { + memPtr := mload(64) + } function constructor_C_11() { diff --git a/test/cmdlineTests/yul_string_format_ascii_long/output.json b/test/cmdlineTests/yul_string_format_ascii_long/output.json index 5b0cdc891..25bc6ac1d 100644 --- a/test/cmdlineTests/yul_string_format_ascii_long/output.json +++ b/test/cmdlineTests/yul_string_format_ascii_long/output.json @@ -13,9 +13,14 @@ object \"C_11\" { constructor_C_11() - codecopy(0, dataoffset(\"C_11_deployed\"), datasize(\"C_11_deployed\")) + let _1 := allocate_unbounded() + codecopy(_1, dataoffset(\"C_11_deployed\"), datasize(\"C_11_deployed\")) - return(0, datasize(\"C_11_deployed\")) + return(_1, datasize(\"C_11_deployed\")) + + function allocate_unbounded() -> memPtr { + memPtr := mload(64) + } function constructor_C_11() { diff --git a/test/cmdlineTests/yul_string_format_hex/output.json b/test/cmdlineTests/yul_string_format_hex/output.json index aa0d349ba..7bead0aec 100644 --- a/test/cmdlineTests/yul_string_format_hex/output.json +++ b/test/cmdlineTests/yul_string_format_hex/output.json @@ -13,9 +13,14 @@ object \"C_11\" { constructor_C_11() - codecopy(0, dataoffset(\"C_11_deployed\"), datasize(\"C_11_deployed\")) + let _1 := allocate_unbounded() + codecopy(_1, dataoffset(\"C_11_deployed\"), datasize(\"C_11_deployed\")) - return(0, datasize(\"C_11_deployed\")) + return(_1, datasize(\"C_11_deployed\")) + + function allocate_unbounded() -> memPtr { + memPtr := mload(64) + } function constructor_C_11() { diff --git a/test/libsolidity/semanticTests/abiEncoderV2/abi_encode_v2_in_function_inherited_in_v1_contract.sol b/test/libsolidity/semanticTests/abiEncoderV2/abi_encode_v2_in_function_inherited_in_v1_contract.sol index ea22588df..5a1ed846a 100644 --- a/test/libsolidity/semanticTests/abiEncoderV2/abi_encode_v2_in_function_inherited_in_v1_contract.sol +++ b/test/libsolidity/semanticTests/abiEncoderV2/abi_encode_v2_in_function_inherited_in_v1_contract.sol @@ -30,6 +30,6 @@ contract C is B { // compileViaYul: also // ---- // test() -> 77 -// gas irOptimized: 133623 +// gas irOptimized: 133635 // gas legacy: 156573 // gas legacyOptimized: 112940 diff --git a/test/libsolidity/semanticTests/abiEncoderV2/abi_encode_v2_in_modifier_used_in_v1_contract.sol b/test/libsolidity/semanticTests/abiEncoderV2/abi_encode_v2_in_modifier_used_in_v1_contract.sol index 3f68dd068..d5eb7b2c5 100644 --- a/test/libsolidity/semanticTests/abiEncoderV2/abi_encode_v2_in_modifier_used_in_v1_contract.sol +++ b/test/libsolidity/semanticTests/abiEncoderV2/abi_encode_v2_in_modifier_used_in_v1_contract.sol @@ -38,5 +38,5 @@ contract C is B { // compileViaYul: also // ---- // test() -> 5, 10 -// gas irOptimized: 92612 +// gas irOptimized: 92624 // gas legacy: 100441 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 c0a1c4a9a..8e9c7ef53 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: 135871 +// gas irOptimized: 135883 // gas legacy: 264410 // gas legacyOptimized: 135699 diff --git a/test/libsolidity/semanticTests/array/function_array_cross_calls.sol b/test/libsolidity/semanticTests/array/function_array_cross_calls.sol index bf7816b51..8a8590434 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: 345942 +// gas irOptimized: 345955 // gas legacy: 500424 // gas legacyOptimized: 309013 diff --git a/test/libsolidity/semanticTests/array/reusing_memory.sol b/test/libsolidity/semanticTests/array/reusing_memory.sol index d8e1bfcb8..08deac565 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: 115528 +// gas irOptimized: 115543 // gas legacy: 127152 // gas legacyOptimized: 113679 diff --git a/test/libsolidity/semanticTests/constructor/arrays_in_constructors.sol b/test/libsolidity/semanticTests/constructor/arrays_in_constructors.sol index d448f55c8..a9f65676b 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: 474619 +// gas irOptimized: 474718 // gas legacy: 570900 // gas legacyOptimized: 436724 diff --git a/test/libsolidity/semanticTests/constructor/bytes_in_constructors_packer.sol b/test/libsolidity/semanticTests/constructor/bytes_in_constructors_packer.sol index 12b9beeb2..e12576a4e 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: 330923 +// gas irOptimized: 330976 // gas legacy: 414850 // gas legacyOptimized: 292281 diff --git a/test/libsolidity/semanticTests/constructor/no_callvalue_check.sol b/test/libsolidity/semanticTests/constructor/no_callvalue_check.sol index b60a7b5ba..10b87a9e0 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: 123725 +// gas irOptimized: 123743 // gas legacy: 123226 // gas legacyOptimized: 123092 diff --git a/test/libsolidity/semanticTests/functionTypes/store_function.sol b/test/libsolidity/semanticTests/functionTypes/store_function.sol index 3ba14b0da..e48ff21e1 100644 --- a/test/libsolidity/semanticTests/functionTypes/store_function.sol +++ b/test/libsolidity/semanticTests/functionTypes/store_function.sol @@ -28,6 +28,6 @@ contract C { // compileViaYul: also // ---- // t() -> 9 -// gas irOptimized: 103941 +// gas irOptimized: 103953 // gas legacy: 161097 // gas legacyOptimized: 112116 diff --git a/test/libsolidity/semanticTests/immutable/multi_creation.sol b/test/libsolidity/semanticTests/immutable/multi_creation.sol index 0f4e3b44b..1b10dd3c5 100644 --- a/test/libsolidity/semanticTests/immutable/multi_creation.sol +++ b/test/libsolidity/semanticTests/immutable/multi_creation.sol @@ -29,7 +29,7 @@ contract C { // compileViaYul: also // ---- // f() -> 3, 7, 5 -// gas irOptimized: 131350 +// gas irOptimized: 131380 // gas legacy: 153990 // gas legacyOptimized: 127822 // x() -> 7 diff --git a/test/libsolidity/semanticTests/inheritance/address_overload_resolution.sol b/test/libsolidity/semanticTests/inheritance/address_overload_resolution.sol index a18f79aac..3f988d9bf 100644 --- a/test/libsolidity/semanticTests/inheritance/address_overload_resolution.sol +++ b/test/libsolidity/semanticTests/inheritance/address_overload_resolution.sol @@ -23,8 +23,8 @@ contract D { // compileViaYul: also // ---- // f() -> 1 -// gas irOptimized: 86492 +// gas irOptimized: 86504 // gas legacy: 114412 // g() -> 5 -// gas irOptimized: 86588 +// gas irOptimized: 86600 // gas legacy: 114872 diff --git a/test/libsolidity/semanticTests/inheritance/inherited_function_calldata_calldata_interface.sol b/test/libsolidity/semanticTests/inheritance/inherited_function_calldata_calldata_interface.sol index 028dfd7db..44688ada4 100644 --- a/test/libsolidity/semanticTests/inheritance/inherited_function_calldata_calldata_interface.sol +++ b/test/libsolidity/semanticTests/inheritance/inherited_function_calldata_calldata_interface.sol @@ -25,5 +25,5 @@ contract B { // compileViaYul: also // ---- // g() -> 42 -// gas irOptimized: 90623 +// gas irOptimized: 90635 // gas legacy: 117797 diff --git a/test/libsolidity/semanticTests/inheritance/inherited_function_calldata_memory_interface.sol b/test/libsolidity/semanticTests/inheritance/inherited_function_calldata_memory_interface.sol index ddc88fe9d..3b5ea5ee8 100644 --- a/test/libsolidity/semanticTests/inheritance/inherited_function_calldata_memory_interface.sol +++ b/test/libsolidity/semanticTests/inheritance/inherited_function_calldata_memory_interface.sol @@ -25,6 +25,6 @@ contract B { // compileViaYul: also // ---- // g() -> 42 -// gas irOptimized: 119646 +// gas irOptimized: 119658 // gas legacy: 180597 // gas legacyOptimized: 117351 diff --git a/test/libsolidity/semanticTests/interface_inheritance_conversions.sol b/test/libsolidity/semanticTests/interface_inheritance_conversions.sol index 8cd65d9bd..a2e45fbc3 100644 --- a/test/libsolidity/semanticTests/interface_inheritance_conversions.sol +++ b/test/libsolidity/semanticTests/interface_inheritance_conversions.sol @@ -37,10 +37,10 @@ contract C { // compileViaYul: also // ---- // convertParent() -> 1 -// gas irOptimized: 103625 +// gas irOptimized: 103637 // convertSubA() -> 1, 2 -// gas irOptimized: 105708 +// gas irOptimized: 105720 // gas legacy: 101703 // convertSubB() -> 1, 3 -// gas irOptimized: 105642 +// gas irOptimized: 105654 // gas legacy: 101637 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 ee3d77253..cc279c917 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: 294216 +// gas irOptimized: 294279 // gas legacy: 422027 // gas legacyOptimized: 287256