diff --git a/libyul/optimiser/Metrics.cpp b/libyul/optimiser/Metrics.cpp index 0af4d4572..a26ea547d 100644 --- a/libyul/optimiser/Metrics.cpp +++ b/libyul/optimiser/Metrics.cpp @@ -70,8 +70,14 @@ size_t CodeWeights::costOf(Expression const& _expression) const return functionCallCost; else if (holds_alternative(_expression)) return identifierCost; - else if (holds_alternative(_expression)) - return literalCost; + else if (Literal const* literal = get_if(&_expression)) + { + // Avoid strings because they could be longer than 32 bytes. + if (literal->kind != LiteralKind::String && valueOfLiteral(*literal) == 0) + return literalZeroCost; + else + return literalCost; + } else yulAssert(false, "If you add a new expression type, you must update CodeWeights."); } diff --git a/libyul/optimiser/Metrics.h b/libyul/optimiser/Metrics.h index 5aa8dbe4b..f86e3b28d 100644 --- a/libyul/optimiser/Metrics.h +++ b/libyul/optimiser/Metrics.h @@ -36,12 +36,13 @@ struct EVMDialect; * The default values are meant to reflect specifically the number of AST nodes. * * The following AST elements have a default cost of zero (because the cleanup phase would - * remove them anyway or they are just wrappers around something else will be counted instead): + * remove them anyway or they are just wrappers around something else that will be counted instead): * - expression statement (only the expression inside has a cost) * - block (only the statements inside have a cost) * - variable references * - variable declarations (only the right hand side has a cost) * - assignments (only the value has a cost) + * - literal zeros (we optimistically assume they can be copied from somewhere else) * * Each statement incurs and additional cost of one * per jump/branch. This means if, break and continue statements have a cost of 2, @@ -68,6 +69,7 @@ struct CodeWeights size_t functionCallCost = 1; size_t identifierCost = 0; size_t literalCost = 1; + size_t literalZeroCost = 0; size_t costOf(Statement const& _statement) const; size_t costOf(Expression const& _expression) const; diff --git a/test/cmdlineTests/evm_to_wasm_break/output b/test/cmdlineTests/evm_to_wasm_break/output index 0eaf827d2..01a4cbb41 100644 --- a/test/cmdlineTests/evm_to_wasm_break/output +++ b/test/cmdlineTests/evm_to_wasm_break/output @@ -40,11 +40,11 @@ object "object" { x_7 := x_11 } { - let _2, _3, _4, _5 := iszero_1300_2121(lt(x_4, x_5, x_6, x_7)) + let _2, _3, _4, _5 := iszero_1324_2108(lt(x_4, x_5, x_6, x_7)) if i32.eqz(i64.eqz(i64.or(i64.or(_2, _3), i64.or(_4, _5)))) { break } - let _6, _7, _8, _9 := eq_740_2122(x_4, x_5, x_6, x_7) + let _6, _7, _8, _9 := eq_771_2109(x_4, x_5, x_6, x_7) if i32.eqz(i64.eqz(i64.or(i64.or(_6, _7), i64.or(_8, _9)))) { break } - let _10, _11, _12, _13 := eq_741_2123(x_4, x_5, x_6, x_7) + let _10, _11, _12, _13 := eq_772_2110(x_4, x_5, x_6, x_7) if i32.eqz(i64.eqz(i64.or(i64.or(_10, _11), i64.or(_12, _13)))) { continue } } sstore(x_4, x_5, x_6, x_7) @@ -59,15 +59,15 @@ object "object" { r2 := i64.add(t_2, i64.extend_i32_u(i32.or(i64.lt_u(t_1, x3), i64.lt_u(r3, t_1)))) r1 := i64.add(i64.add(x1, 0), i64.extend_i32_u(i32.or(i64.lt_u(t_2, x2), i64.lt_u(r2, t_2)))) } - function iszero_1300_2121(x4) -> r1, r2, r3, r4 + function iszero_1324_2108(x4) -> r1, r2, r3, r4 { r4 := i64.extend_i32_u(i64.eqz(i64.or(i64.or(0, 0), i64.or(0, x4)))) } - function eq_740_2122(x1, x2, x3, x4) -> r1, r2, r3, r4 + function eq_771_2109(x1, x2, x3, x4) -> r1, r2, r3, r4 { r4 := i64.extend_i32_u(i32.and(i64.eq(x1, 0), i32.and(i64.eq(x2, 0), i32.and(i64.eq(x3, 0), i64.eq(x4, 2))))) } - function eq_741_2123(x1, x2, x3, x4) -> r1, r2, r3, r4 + function eq_772_2110(x1, x2, x3, x4) -> r1, r2, r3, r4 { r4 := i64.extend_i32_u(i32.and(i64.eq(x1, 0), i32.and(i64.eq(x2, 0), i32.and(i64.eq(x3, 0), i64.eq(x4, 4))))) } @@ -92,19 +92,19 @@ object "object" { default { z := 1:i32 } z4 := i64.extend_i32_u(z) } - function u256_to_i32_744() -> v:i32 - { - if i64.ne(0, i64.or(i64.or(0, 0), 0)) { unreachable() } - if i64.ne(0, i64.shr_u(32, 32)) { unreachable() } - v := i32.wrap_i64(32) - } - function u256_to_i32() -> v:i32 + function u256_to_i32_774() -> v:i32 { let _1 := 0 if i64.ne(_1, i64.or(i64.or(_1, _1), _1)) { unreachable() } if i64.ne(_1, i64.shr_u(_1, 32)) { unreachable() } v := i32.wrap_i64(_1) } + function u256_to_i32() -> v:i32 + { + if i64.ne(0, i64.or(i64.or(0, 0), 0)) { unreachable() } + if i64.ne(0, i64.shr_u(32, 32)) { unreachable() } + v := i32.wrap_i64(32) + } function bswap16(x:i32) -> y:i32 { y := i32.or(i32.and(i32.shl(x, 8:i32), 0xff00:i32), i32.and(i32.shr_u(x, 8:i32), 0xff:i32)) @@ -122,31 +122,31 @@ object "object" { function calldataload() -> z1, z2, z3, z4 { let cds:i32 := eth.getCallDataSize() - let _1 := 0 - if i64.ne(_1, i64.or(i64.or(_1, _1), _1)) { unreachable() } - if i64.ne(_1, i64.shr_u(_1, 32)) { unreachable() } - let v:i32 := i32.wrap_i64(_1) - let offset:i32 := u256_to_i32() - let requested_size:i32 := u256_to_i32_744() + let destination:i32 := u256_to_i32_774() + let offset:i32 := u256_to_i32_774() + let requested_size:i32 := u256_to_i32() if i32.gt_u(offset, i32.sub(0xffffffff:i32, requested_size)) { eth.revert(0:i32, 0:i32) } let available_size:i32 := i32.sub(cds, offset) if i32.gt_u(offset, cds) { available_size := 0:i32 } - let _2:i32 := 0:i32 - if i32.gt_u(available_size, _2) + let _1:i32 := 0:i32 + if i32.gt_u(available_size, _1) { - eth.callDataCopy(v, offset, available_size) + eth.callDataCopy(destination, offset, available_size) } if i32.gt_u(requested_size, available_size) { - let _3:i32 := i32.sub(requested_size, available_size) - let _4:i32 := i32.add(v, available_size) - let i:i32 := _2 - for { } i32.lt_u(i, _3) { i := i32.add(i, 1:i32) } + let _2:i32 := i32.sub(requested_size, available_size) + let _3:i32 := i32.add(destination, available_size) + let i:i32 := _1 + for { } i32.lt_u(i, _2) { i := i32.add(i, 1:i32) } { - i32.store8(i32.add(_4, i), _2) + i32.store8(i32.add(_3, i), _1) } } - let z1_1, z2_1, z3_1, z4_1 := mload_internal() + let z1_1 := bswap64(i64.load(_1)) + let z2_1 := bswap64(i64.load(i32.add(_1, 8:i32))) + let z3_1 := bswap64(i64.load(i32.add(_1, 16:i32))) + let z4_1 := bswap64(i64.load(i32.add(_1, 24:i32))) z1 := z1_1 z2 := z2_1 z3 := z3_1 @@ -166,19 +166,12 @@ object "object" { i64.store(i32.add(32:i32, 24:i32), bswap64(y4)) eth.storageStore(0:i32, 32:i32) } - function mload_internal() -> z1, z2, z3, z4 - { - z1 := bswap64(i64.load(0:i32)) - z2 := bswap64(i64.load(i32.add(0:i32, 8:i32))) - z3 := bswap64(i64.load(i32.add(0:i32, 16:i32))) - z4 := bswap64(i64.load(i32.add(0:i32, 24:i32))) - } } } Binary representation: -0061736d010000000130096000006000017e6000017f60017e017e60047e7e7e7e0060047e7e7e7e017e60017f017f60027f7f0060037f7f7f00025e0408657468657265756d0c73746f7261676553746f7265000708657468657265756d06726576657274000708657468657265756d0f67657443616c6c4461746153697a65000208657468657265756d0c63616c6c44617461436f70790008030f0e00050305050502020606030104010503010001061a057e0142000b7e0142000b7e0142000b7f0141000b7f0141000b071102066d656d6f72790200046d61696e00040a8a0a0e8d0203087e017f107e02400240100f21002300210123012102230221030b200021042001210520022106200321074200420084420042018484504545210802400340200845450d010240024020042005200620071009100621092303210a2304210b2300210c0b2009200a84200b200c8484504504400c030b024020042005200620071007210d2300210e2301210f230221100b200d200e84200f20108484504504400c030b02402004200520062007100821112300211223012113230221140b2011201284201320148484504504400c010b0b02402004200520062007100521152300211623012117230221180b201521042016210520172106201821070c000b0b200420052006200710100b0b6701077e0240200342017c2108200842007c2107200242007c210920092008200354200720085472ad7c2106200142007c210a200a2009200254200620095472ad7c2105200042007c200a2001542005200a5472ad7c21040b20052400200624012007240220040b2401047e0240420042008442002000848450ad21040b20022400200324012004240220010b2f01047e02402000420051200142005120024200512003420251717171ad21070b20052400200624012007240220040b2f01047e02402000420051200142005120024200512003420451717171ad21070b20052400200624012007240220040bab0104017e017f017e047f02404100210542002106417f210702402007200020065220002006541b21082008410046044002402007200120065220012006541b21092009410046044002402007200220065220022006541b210a200a41004604402003420a54210505200a41014604404100210505410121050b0b0b05200941014604404100210505410121050b0b0b05200841014604404100210505410121050b0b0b2005ad21040b20040b2901017f024042004200420084420084520440000b42004220422088520440000b4220a721000b20000b2f02017f017e02404200210120012001200184200184520440000b20012001422088520440000b2001a721000b20000b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100c411074210220022000411076100c7221010b20010b2201027e02402000a7100dad422086210220022000422088a7100dad8421010b20010be60105047e017f017e087f047e0240100221044200210520052005200584200584520440000b20052005422088520440000b2005a72106100b2107100a21082007417f20086b4b04404100410010010b200420076b2109200720044b0440410021090b4100210a2009200a4b044020062007200910030b200820094b0440200820096b210b200620096a210c200a210d02400340200d200b49450d010240200c200d6a200a3a00000b200d41016a210d0c000b0b0b02401011210e2300210f23012110230221110b200e2100200f210120102102201121030b20012400200224012003240220000b7801027e02404200a7100dad422086210420044200422088a7100dad84210541002005370000410041086a2005370000410041106a2005370000410041186a200537000041202000100e370000412041086a2001100e370000412041106a2002100e370000412041186a2003100e3700004100412010000b0b4201047e02404100290000100e2100410041086a290000100e2101410041106a290000100e2102410041186a290000100e21030b20012400200224012003240220000b +0061736d010000000130096000006000017e6000017f60017e017e60047e7e7e7e0060047e7e7e7e017e60017f017f60027f7f0060037f7f7f00025e0408657468657265756d0c73746f7261676553746f7265000708657468657265756d06726576657274000708657468657265756d0f67657443616c6c4461746153697a65000208657468657265756d0c63616c6c44617461436f70790008030e0d0005030505050202060603010405030100010615047e0142000b7e0142000b7e0142000b7f0141000b071102066d656d6f72790200046d61696e00040abd090d8d0203087e017f107e02400240100f21002300210123012102230221030b200021042001210520022106200321074200420084420042018484504545210802400340200845450d010240024020042005200620071009100621092303210a2300210b2301210c0b2009200a84200b200c8484504504400c030b024020042005200620071007210d2300210e2301210f230221100b200d200e84200f20108484504504400c030b02402004200520062007100821112300211223012113230221140b2011201284201320148484504504400c010b0b02402004200520062007100521152300211623012117230221180b201521042016210520172106201821070c000b0b200420052006200710100b0b6701077e0240200342017c2108200842007c2107200242007c210920092008200354200720085472ad7c2106200142007c210a200a2009200254200620095472ad7c2105200042007c200a2001542005200a5472ad7c21040b20052400200624012007240220040b2401047e0240420042008442002000848450ad21040b20022400200324012004240220010b2f01047e02402000420051200142005120024200512003420251717171ad21070b20052400200624012007240220040b2f01047e02402000420051200142005120024200512003420451717171ad21070b20052400200624012007240220040bab0104017e017f017e047f02404100210542002106417f210702402007200020065220002006541b21082008410046044002402007200120065220012006541b21092009410046044002402007200220065220022006541b210a200a41004604402003420a54210505200a41014604404100210505410121050b0b0b05200941014604404100210505410121050b0b0b05200841014604404100210505410121050b0b0b2005ad21040b20040b2f02017f017e02404200210120012001200184200184520440000b20012001422088520440000b2001a721000b20000b2901017f024042004200420084420084520440000b42004220422088520440000b4220a721000b20000b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100c411074210220022000411076100c7221010b20010b2201027e02402000a7100dad422086210220022000422088a7100dad8421010b20010bdc0103047e097f047e024010022104100a2105100a2106100b21072006417f20076b4b04404100410010010b200420066b2108200620044b0440410021080b41002109200820094b044020052006200810030b200720084b0440200720086b210a200520086a210b2009210c02400340200c200a49450d010240200b200c6a20093a00000b200c41016a210c0c000b0b0b2009290000100e210d200941086a290000100e210e200941106a290000100e210f200941186a290000100e2110200d2100200e2101200f2102201021030b20012400200224012003240220000b7801027e02404200a7100dad422086210420044200422088a7100dad84210541002005370000410041086a2005370000410041106a2005370000410041186a200537000041202000100e370000412041086a2001100e370000412041106a2002100e370000412041186a2003100e3700004100412010000b0b Text representation: (module @@ -192,7 +185,6 @@ Text representation: (global $global__1 (mut i64) (i64.const 0)) (global $global__2 (mut i64) (i64.const 0)) (global $global__6 (mut i32) (i32.const 0)) - (global $global__7 (mut i32) (i32.const 0)) (func $main (local $x i64) @@ -238,17 +230,17 @@ Text representation: (br_if $label__3 (i32.eqz (i32.eqz (local.get $_1)))) (block $label__4 (block - (local.set $_2 (call $iszero_1300_2121 (call $lt (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7)))) + (local.set $_2 (call $iszero_1324_2108 (call $lt (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7)))) (local.set $_3 (global.get $global__6)) - (local.set $_4 (global.get $global__7)) - (local.set $_5 (global.get $global_)) + (local.set $_4 (global.get $global_)) + (local.set $_5 (global.get $global__1)) ) (if (i32.eqz (i64.eqz (i64.or (i64.or (local.get $_2) (local.get $_3)) (i64.or (local.get $_4) (local.get $_5))))) (then (br $label__3) )) (block - (local.set $_6 (call $eq_740_2122 (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7))) + (local.set $_6 (call $eq_771_2109 (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7))) (local.set $_7 (global.get $global_)) (local.set $_8 (global.get $global__1)) (local.set $_9 (global.get $global__2)) @@ -258,7 +250,7 @@ Text representation: (br $label__3) )) (block - (local.set $_10 (call $eq_741_2123 (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7))) + (local.set $_10 (call $eq_772_2110 (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7))) (local.set $_11 (global.get $global_)) (local.set $_12 (global.get $global__1)) (local.set $_13 (global.get $global__2)) @@ -301,7 +293,7 @@ Text representation: (local $t i64) (local $t_1 i64) (local $t_2 i64) - (block $label__8 + (block $label__7 (local.set $t (i64.add (local.get $x4) (i64.const 1))) (local.set $r4 (i64.add (local.get $t) (i64.const 0))) (local.set $t_1 (i64.add (local.get $x3) (i64.const 0))) @@ -317,14 +309,14 @@ Text representation: (local.get $r1) ) -(func $iszero_1300_2121 +(func $iszero_1324_2108 (param $x4 i64) (result i64) (local $r1 i64) (local $r2 i64) (local $r3 i64) (local $r4 i64) - (block $label__9 + (block $label__8 (local.set $r4 (i64.extend_i32_u (i64.eqz (i64.or (i64.or (i64.const 0) (i64.const 0)) (i64.or (i64.const 0) (local.get $x4)))))) ) @@ -334,7 +326,27 @@ Text representation: (local.get $r1) ) -(func $eq_740_2122 +(func $eq_771_2109 + (param $x1 i64) + (param $x2 i64) + (param $x3 i64) + (param $x4 i64) + (result i64) + (local $r1 i64) + (local $r2 i64) + (local $r3 i64) + (local $r4 i64) + (block $label__9 + (local.set $r4 (i64.extend_i32_u (i32.and (i64.eq (local.get $x1) (i64.const 0)) (i32.and (i64.eq (local.get $x2) (i64.const 0)) (i32.and (i64.eq (local.get $x3) (i64.const 0)) (i64.eq (local.get $x4) (i64.const 2))))))) + + ) + (global.set $global_ (local.get $r2)) + (global.set $global__1 (local.get $r3)) + (global.set $global__2 (local.get $r4)) + (local.get $r1) +) + +(func $eq_772_2110 (param $x1 i64) (param $x2 i64) (param $x3 i64) @@ -345,26 +357,6 @@ Text representation: (local $r3 i64) (local $r4 i64) (block $label__10 - (local.set $r4 (i64.extend_i32_u (i32.and (i64.eq (local.get $x1) (i64.const 0)) (i32.and (i64.eq (local.get $x2) (i64.const 0)) (i32.and (i64.eq (local.get $x3) (i64.const 0)) (i64.eq (local.get $x4) (i64.const 2))))))) - - ) - (global.set $global_ (local.get $r2)) - (global.set $global__1 (local.get $r3)) - (global.set $global__2 (local.get $r4)) - (local.get $r1) -) - -(func $eq_741_2123 - (param $x1 i64) - (param $x2 i64) - (param $x3 i64) - (param $x4 i64) - (result i64) - (local $r1 i64) - (local $r2 i64) - (local $r3 i64) - (local $r4 i64) - (block $label__11 (local.set $r4 (i64.extend_i32_u (i32.and (i64.eq (local.get $x1) (i64.const 0)) (i32.and (i64.eq (local.get $x2) (i64.const 0)) (i32.and (i64.eq (local.get $x3) (i64.const 0)) (i64.eq (local.get $x4) (i64.const 4))))))) ) @@ -385,9 +377,9 @@ Text representation: (local $_1 i64) (local $_2 i32) (local $condition i32) + (local $condition_12 i32) (local $condition_13 i32) - (local $condition_14 i32) - (block $label__12 + (block $label__11 (local.set $z (i32.const 0)) (local.set $_1 (i64.const 0)) (local.set $_2 (i32.const 4294967295)) @@ -395,14 +387,14 @@ Text representation: (local.set $condition (select (local.get $_2) (i64.ne (local.get $x1) (local.get $_1)) (i64.lt_u (local.get $x1) (local.get $_1)))) (if (i32.eq (local.get $condition) (i32.const 0)) (then (block - (local.set $condition_13 (select (local.get $_2) (i64.ne (local.get $x2) (local.get $_1)) (i64.lt_u (local.get $x2) (local.get $_1)))) - (if (i32.eq (local.get $condition_13) (i32.const 0)) (then + (local.set $condition_12 (select (local.get $_2) (i64.ne (local.get $x2) (local.get $_1)) (i64.lt_u (local.get $x2) (local.get $_1)))) + (if (i32.eq (local.get $condition_12) (i32.const 0)) (then (block - (local.set $condition_14 (select (local.get $_2) (i64.ne (local.get $x3) (local.get $_1)) (i64.lt_u (local.get $x3) (local.get $_1)))) - (if (i32.eq (local.get $condition_14) (i32.const 0)) (then + (local.set $condition_13 (select (local.get $_2) (i64.ne (local.get $x3) (local.get $_1)) (i64.lt_u (local.get $x3) (local.get $_1)))) + (if (i32.eq (local.get $condition_13) (i32.const 0)) (then (local.set $z (i64.lt_u (local.get $x4) (i64.const 10))) )(else - (if (i32.eq (local.get $condition_14) (i32.const 1)) (then + (if (i32.eq (local.get $condition_13) (i32.const 1)) (then (local.set $z (i32.const 0)) )(else (local.set $z (i32.const 1)) @@ -411,7 +403,7 @@ Text representation: ) )(else - (if (i32.eq (local.get $condition_13) (i32.const 1)) (then + (if (i32.eq (local.get $condition_12) (i32.const 1)) (then (local.set $z (i32.const 0)) )(else (local.set $z (i32.const 1)) @@ -434,7 +426,23 @@ Text representation: (local.get $z4) ) -(func $u256_to_i32_744 +(func $u256_to_i32_774 + (result i32) + (local $v i32) + (local $_1 i64) + (block $label__14 + (local.set $_1 (i64.const 0)) + (if (i64.ne (local.get $_1) (i64.or (i64.or (local.get $_1) (local.get $_1)) (local.get $_1))) (then + (unreachable))) + (if (i64.ne (local.get $_1) (i64.shr_u (local.get $_1) (i64.const 32))) (then + (unreachable))) + (local.set $v (i32.wrap_i64 (local.get $_1))) + + ) + (local.get $v) +) + +(func $u256_to_i32 (result i32) (local $v i32) (block $label__15 @@ -448,27 +456,11 @@ Text representation: (local.get $v) ) -(func $u256_to_i32 - (result i32) - (local $v i32) - (local $_1 i64) - (block $label__16 - (local.set $_1 (i64.const 0)) - (if (i64.ne (local.get $_1) (i64.or (i64.or (local.get $_1) (local.get $_1)) (local.get $_1))) (then - (unreachable))) - (if (i64.ne (local.get $_1) (i64.shr_u (local.get $_1) (i64.const 32))) (then - (unreachable))) - (local.set $v (i32.wrap_i64 (local.get $_1))) - - ) - (local.get $v) -) - (func $bswap16 (param $x i32) (result i32) (local $y i32) - (block $label__17 + (block $label__16 (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)))) ) @@ -480,7 +472,7 @@ Text representation: (result i32) (local $y i32) (local $hi i32) - (block $label__18 + (block $label__17 (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))))) @@ -493,7 +485,7 @@ Text representation: (result i64) (local $y i64) (local $hi i64) - (block $label__19 + (block $label__18 (local.set $hi (i64.shl (i64.extend_i32_u (call $bswap32 (i32.wrap_i64 (local.get $x)))) (i64.const 32))) (local.set $y (i64.or (local.get $hi) (i64.extend_i32_u (call $bswap32 (i32.wrap_i64 (i64.shr_u (local.get $x) (i64.const 32))))))) @@ -508,61 +500,52 @@ Text representation: (local $z3 i64) (local $z4 i64) (local $cds i32) - (local $_1 i64) - (local $v i32) + (local $destination i32) (local $offset i32) (local $requested_size i32) (local $available_size i32) + (local $_1 i32) (local $_2 i32) (local $_3 i32) - (local $_4 i32) (local $i i32) (local $z1_1 i64) (local $z2_1 i64) (local $z3_1 i64) (local $z4_1 i64) - (block $label__20 + (block $label__19 (local.set $cds (call $eth.getCallDataSize)) - (local.set $_1 (i64.const 0)) - (if (i64.ne (local.get $_1) (i64.or (i64.or (local.get $_1) (local.get $_1)) (local.get $_1))) (then - (unreachable))) - (if (i64.ne (local.get $_1) (i64.shr_u (local.get $_1) (i64.const 32))) (then - (unreachable))) - (local.set $v (i32.wrap_i64 (local.get $_1))) - (local.set $offset (call $u256_to_i32)) - (local.set $requested_size (call $u256_to_i32_744)) + (local.set $destination (call $u256_to_i32_774)) + (local.set $offset (call $u256_to_i32_774)) + (local.set $requested_size (call $u256_to_i32)) (if (i32.gt_u (local.get $offset) (i32.sub (i32.const 4294967295) (local.get $requested_size))) (then (call $eth.revert (i32.const 0) (i32.const 0)))) (local.set $available_size (i32.sub (local.get $cds) (local.get $offset))) (if (i32.gt_u (local.get $offset) (local.get $cds)) (then (local.set $available_size (i32.const 0)) )) - (local.set $_2 (i32.const 0)) - (if (i32.gt_u (local.get $available_size) (local.get $_2)) (then - (call $eth.callDataCopy (local.get $v) (local.get $offset) (local.get $available_size)))) + (local.set $_1 (i32.const 0)) + (if (i32.gt_u (local.get $available_size) (local.get $_1)) (then + (call $eth.callDataCopy (local.get $destination) (local.get $offset) (local.get $available_size)))) (if (i32.gt_u (local.get $requested_size) (local.get $available_size)) (then - (local.set $_3 (i32.sub (local.get $requested_size) (local.get $available_size))) - (local.set $_4 (i32.add (local.get $v) (local.get $available_size))) - (local.set $i (local.get $_2)) - (block $label__21 - (loop $label__23 - (br_if $label__21 (i32.eqz (i32.lt_u (local.get $i) (local.get $_3)))) - (block $label__22 - (i32.store8 (i32.add (local.get $_4) (local.get $i)) (local.get $_2)) + (local.set $_2 (i32.sub (local.get $requested_size) (local.get $available_size))) + (local.set $_3 (i32.add (local.get $destination) (local.get $available_size))) + (local.set $i (local.get $_1)) + (block $label__20 + (loop $label__22 + (br_if $label__20 (i32.eqz (i32.lt_u (local.get $i) (local.get $_2)))) + (block $label__21 + (i32.store8 (i32.add (local.get $_3) (local.get $i)) (local.get $_1)) ) (local.set $i (i32.add (local.get $i) (i32.const 1))) - (br $label__23) + (br $label__22) ) ) )) - (block - (local.set $z1_1 (call $mload_internal)) - (local.set $z2_1 (global.get $global_)) - (local.set $z3_1 (global.get $global__1)) - (local.set $z4_1 (global.get $global__2)) - - ) + (local.set $z1_1 (call $bswap64 (i64.load (local.get $_1)))) + (local.set $z2_1 (call $bswap64 (i64.load (i32.add (local.get $_1) (i32.const 8))))) + (local.set $z3_1 (call $bswap64 (i64.load (i32.add (local.get $_1) (i32.const 16))))) + (local.set $z4_1 (call $bswap64 (i64.load (i32.add (local.get $_1) (i32.const 24))))) (local.set $z1 (local.get $z1_1)) (local.set $z2 (local.get $z2_1)) (local.set $z3 (local.get $z3_1)) @@ -582,7 +565,7 @@ Text representation: (param $y4 i64) (local $hi i64) (local $y i64) - (block $label__24 + (block $label__23 (local.set $hi (i64.shl (i64.extend_i32_u (call $bswap32 (i32.wrap_i64 (i64.const 0)))) (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 0) (i64.const 32))))))) (i64.store (i32.const 0) (local.get $y)) @@ -597,23 +580,4 @@ Text representation: ) ) -(func $mload_internal - (result i64) - (local $z1 i64) - (local $z2 i64) - (local $z3 i64) - (local $z4 i64) - (block $label__25 - (local.set $z1 (call $bswap64 (i64.load (i32.const 0)))) - (local.set $z2 (call $bswap64 (i64.load (i32.add (i32.const 0) (i32.const 8))))) - (local.set $z3 (call $bswap64 (i64.load (i32.add (i32.const 0) (i32.const 16))))) - (local.set $z4 (call $bswap64 (i64.load (i32.add (i32.const 0) (i32.const 24))))) - - ) - (global.set $global_ (local.get $z2)) - (global.set $global__1 (local.get $z3)) - (global.set $global__2 (local.get $z4)) - (local.get $z1) -) - ) diff --git a/test/cmdlineTests/optimizer_array_sload/output b/test/cmdlineTests/optimizer_array_sload/output index 37a92d63e..9e277fb17 100644 --- a/test/cmdlineTests/optimizer_array_sload/output +++ b/test/cmdlineTests/optimizer_array_sload/output @@ -38,7 +38,9 @@ object "Arraysum_34" { } { mstore(_1, _1) - var_sum := checked_add_uint256(var_sum, sload(add(keccak256(_1, 0x20), var_i))) + let _3 := sload(add(keccak256(_1, 0x20), var_i)) + if gt(var_sum, not(_3)) { panic_error_0x11() } + var_sum := add(var_sum, _3) } let memPos := mload(64) return(memPos, sub(abi_encode_uint256(memPos, var_sum), memPos)) @@ -51,11 +53,6 @@ object "Arraysum_34" { tail := add(headStart, 32) mstore(headStart, value0) } - function checked_add_uint256(x, y) -> sum - { - if gt(x, not(y)) { panic_error_0x11() } - sum := add(x, y) - } function panic_error_0x11() { mstore(0, shl(224, 0x4e487b71)) diff --git a/test/cmdlineTests/standard_ewasm_requested/output.json b/test/cmdlineTests/standard_ewasm_requested/output.json index 40e7ca65f..60a59e7fe 100644 --- a/test/cmdlineTests/standard_ewasm_requested/output.json +++ b/test/cmdlineTests/standard_ewasm_requested/output.json @@ -1,7 +1,7 @@ -{"contracts":{"A":{"C":{"ewasm":{"wasm":"0061736d0100000001330b6000006000017e6000017f60017e0060017e017e60017e017f60027e7e0060017f0060017f017f60027f7f0060037f7f7f0002510408657468657265756d08636f6465436f7079000a08657468657265756d06726576657274000908657468657265756d0c67657443616c6c56616c7565000708657468657265756d0666696e6973680009030d0c0002050208080101040603000503010001060100071102066d656d6f72790200046d61696e00040092030c435f335f6465706c6f7965640061736d010000000112046000006000017f60017f017f60027f7f0002130108657468657265756d06726576657274000303060500010102020503010001060100071102066d656d6f72790200046d61696e00010aae02059d0103017e027f037e02404200210020002000200084200084520440000b200042c000422088520440000b42c000a72101200141c0006a210220022001490440000b2000a71005ad422086210320032000422088a71005ad84210420022004370000200241086a2004370000200241106a2004370000428001a71005ad4220862105200241186a2005428001422088a71005ad843700001003100210000b0b2f02017f017e02404200210120012001200184200184520440000b20012001422088520440000b2001a721000b20000b1e01027f024010022101200141c0006a210020002001490440000b0b20000b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100441107421022002200041107610047221010b20010b0aca040c960102027f057e024010052100200041c0006a210120012000490440000b100a210220012002370000200141086a2002370000200141106a2002370000200141186a100b370000410010024100290000100c2103410041086a290000100c2104410041106a290000100c210520032004842005410041186a290000100c848450450440100f0b428503210642ca012006100d2006100e0b0b2b01017f024042004200420084420084520440000b420042c000422088520440000b42c000a721000b20000b2901017f024042004200420084420084520440000b42002000422088520440000b2000a721010b20010b2f02017f017e02404200210120012001200184200184520440000b20012001422088520440000b2001a721000b20000b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100841107421022002200041107610087221010b20010b2201027e02404200a71009ad422086210120014200422088a71009ad8421000b20000b2401027e0240428001a71009ad42208621012001428001422088a71009ad8421000b20000b2201027e02402000a71009ad422086210220022000422088a71009ad8421010b20010b3001047f024020011006210220001006210310072104200441c0006a210520052004490440000b20052003200210000b0b2801037f024020001006210110072102200241c0006a210320032002490440000b2003200110030b0b2601037f02401007210010072101200141c0006a210220022001490440000b2002200010010b0b","wast":"(module +{"contracts":{"A":{"C":{"ewasm":{"wasm":"0061736d0100000001330b6000006000017e6000017f60017e0060017e017e60017e017f60027e7e0060017f0060017f017f60027f7f0060037f7f7f0002510408657468657265756d08636f6465436f7079000a08657468657265756d06726576657274000908657468657265756d0c67657443616c6c56616c7565000708657468657265756d0666696e6973680009030c0b00050208080101040603000503010001060100071102066d656d6f72790200046d61696e000400b6030c435f335f6465706c6f7965640061736d010000000112046000006000017f60017f017f60027f7f0002130108657468657265756d06726576657274000303060500010102020503010001060100071102066d656d6f72790200046d61696e00010ad20205a10104027f017e017f047e024010022100200041c0006a210120012000490440000b420021022002a7210320031005ad42208621042002422088210520042005a71005ad84210620012006370000200141086a2006370000200141106a2006370000428001a71005ad4220862107200141186a2007428001422088a71005ad8437000020022002200284200284520440000b20022005520440000b1003200310000b0b2b01017f024042004200420084420084520440000b420042c000422088520440000b42c000a721000b20000b4203017f017e017f02404200210120012001200184200184520440000b20012001422088520440000b2001a72102200241c0006a210020002002490440000b0b20000b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100441107421022002200041107610047221010b20010b0abc040bb40102027f057e024042004200420084420084520440000b420042c000422088520440000b42c000a72100200041c0006a210120012000490440000b1009210220012002370000200141086a2002370000200141106a2002370000200141186a100a370000410010024100290000100b2103410041086a290000100b2104410041106a290000100b210520032004842005410041186a290000100b848450450440100e0b42a903210642c9012006100c2006100d0b0b2901017f024042004200420084420084520440000b42002000422088520440000b2000a721010b20010b2f02017f017e02404200210120012001200184200184520440000b20012001422088520440000b2001a721000b20000b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100741107421022002200041107610077221010b20010b2201027e02404200a71008ad422086210120014200422088a71008ad8421000b20000b2401027e0240428001a71008ad42208621012001428001422088a71008ad8421000b20000b2201027e02402000a71008ad422086210220022000422088a71008ad8421010b20010b3001047f024020011005210220001005210310062104200441c0006a210520052004490440000b20052003200210000b0b2801037f024020001005210110062102200241c0006a210320032002490440000b2003200110030b0b2601037f02401006210010062101200141c0006a210220022001490440000b2002200010010b0b","wast":"(module ;; custom section for sub-module - ;; The Keccak-256 hash of the text representation of \"C_3_deployed\": 1c21519afc0397d3ba45d99eb2354c3d74191cd82bffab348d52efabddb63f6a - ;; (@custom \"C_3_deployed\" \"0061736d010000000112046000006000017f60017f017f60027f7f0002130108657468657265756d06726576657274000303060500010102020503010001060100071102066d656d6f72790200046d61696e00010aae02059d0103017e027f037e02404200210020002000200084200084520440000b200042c000422088520440000b42c000a72101200141c0006a210220022001490440000b2000a71005ad422086210320032000422088a71005ad84210420022004370000200241086a2004370000200241106a2004370000428001a71005ad4220862105200241186a2005428001422088a71005ad843700001003100210000b0b2f02017f017e02404200210120012001200184200184520440000b20012001422088520440000b2001a721000b20000b1e01027f024010022101200141c0006a210020002001490440000b0b20000b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100441107421022002200041107610047221010b20010b\") + ;; The Keccak-256 hash of the text representation of \"C_3_deployed\": d5523336521d49fa8bd64dba28ece7291aa7d45c646a23eabd038bbeecc2d803 + ;; (@custom \"C_3_deployed\" \"0061736d010000000112046000006000017f60017f017f60027f7f0002130108657468657265756d06726576657274000303060500010102020503010001060100071102066d656d6f72790200046d61696e00010ad20205a10104027f017e017f047e024010022100200041c0006a210120012000490440000b420021022002a7210320031005ad42208621042002422088210520042005a71005ad84210620012006370000200141086a2006370000200141106a2006370000428001a71005ad4220862107200141186a2007428001422088a71005ad8437000020022002200284200284520440000b20022005520440000b1003200310000b0b2b01017f024042004200420084420084520440000b420042c000422088520440000b42c000a721000b20000b4203017f017e017f02404200210120012001200184200184520440000b20012001422088520440000b2001a72102200241c0006a210020002002490440000b0b20000b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100441107421022002200041107610047221010b20010b\") (import \"ethereum\" \"codeCopy\" (func $eth.codeCopy (param i32 i32 i32))) (import \"ethereum\" \"revert\" (func $eth.revert (param i32 i32))) (import \"ethereum\" \"getCallValue\" (func $eth.getCallValue (param i32))) @@ -10,7 +10,7 @@ (export \"main\" (func $main)) (func $main - (local $p i32) + (local $v i32) (local $r i32) (local $_1 i64) (local $z1 i64) @@ -18,9 +18,13 @@ (local $z3 i64) (local $_2 i64) (block $label_ - (local.set $p (call $u256_to_i32_685)) - (local.set $r (i32.add (local.get $p) (i32.const 64))) - (if (i32.lt_u (local.get $r) (local.get $p)) (then + (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 64) (i64.const 32))) (then + (unreachable))) + (local.set $v (i32.wrap_i64 (i64.const 64))) + (local.set $r (i32.add (local.get $v) (i32.const 64))) + (if (i32.lt_u (local.get $r) (local.get $v)) (then (unreachable))) (local.set $_1 (call $bswap64_388)) (i64.store (local.get $r) (local.get $_1)) @@ -39,25 +43,11 @@ ) ) -(func $u256_to_i32_685 - (result i32) - (local $v i32) - (block $label__1 - (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 64) (i64.const 32))) (then - (unreachable))) - (local.set $v (i32.wrap_i64 (i64.const 64))) - - ) - (local.get $v) -) - (func $u256_to_i32_687 (param $x4 i64) (result i32) (local $v i32) - (block $label__2 + (block $label__1 (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 (local.get $x4) (i64.const 32))) (then @@ -72,7 +62,7 @@ (result i32) (local $v i32) (local $_1 i64) - (block $label__3 + (block $label__2 (local.set $_1 (i64.const 0)) (if (i64.ne (local.get $_1) (i64.or (i64.or (local.get $_1) (local.get $_1)) (local.get $_1))) (then (unreachable))) @@ -88,7 +78,7 @@ (param $x i32) (result i32) (local $y i32) - (block $label__4 + (block $label__3 (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)))) ) @@ -100,7 +90,7 @@ (result i32) (local $y i32) (local $hi i32) - (block $label__5 + (block $label__4 (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))))) @@ -112,7 +102,7 @@ (result i64) (local $y i64) (local $hi i64) - (block $label__6 + (block $label__5 (local.set $hi (i64.shl (i64.extend_i32_u (call $bswap32 (i32.wrap_i64 (i64.const 0)))) (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 0) (i64.const 32))))))) @@ -124,7 +114,7 @@ (result i64) (local $y i64) (local $hi i64) - (block $label__7 + (block $label__6 (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))))))) @@ -137,7 +127,7 @@ (result i64) (local $y i64) (local $hi i64) - (block $label__8 + (block $label__7 (local.set $hi (i64.shl (i64.extend_i32_u (call $bswap32 (i32.wrap_i64 (local.get $x)))) (i64.const 32))) (local.set $y (i64.or (local.get $hi) (i64.extend_i32_u (call $bswap32 (i32.wrap_i64 (i64.shr_u (local.get $x) (i64.const 32))))))) @@ -152,7 +142,7 @@ (local $_2 i32) (local $p i32) (local $r i32) - (block $label__9 + (block $label__8 (local.set $_1 (call $u256_to_i32_687 (local.get $z4))) (local.set $_2 (call $u256_to_i32_687 (local.get $y4))) (local.set $p (call $u256_to_i32)) @@ -168,7 +158,7 @@ (local $_1 i32) (local $p i32) (local $r i32) - (block $label__10 + (block $label__9 (local.set $_1 (call $u256_to_i32_687 (local.get $y4))) (local.set $p (call $u256_to_i32)) (local.set $r (i32.add (local.get $p) (i32.const 64))) @@ -182,7 +172,7 @@ (local $_1 i32) (local $p i32) (local $r i32) - (block $label__11 + (block $label__10 (local.set $_1 (call $u256_to_i32)) (local.set $p (call $u256_to_i32)) (local.set $r (i32.add (local.get $p) (i32.const 64))) 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 2827b89bb..3f68dd068 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: 92642 +// gas irOptimized: 92612 // gas legacy: 100441 diff --git a/test/libsolidity/semanticTests/array/bytes_length_member.sol b/test/libsolidity/semanticTests/array/bytes_length_member.sol index dab3d6bf4..17cb0c10f 100644 --- a/test/libsolidity/semanticTests/array/bytes_length_member.sol +++ b/test/libsolidity/semanticTests/array/bytes_length_member.sol @@ -15,7 +15,7 @@ contract c { // ---- // getLength() -> 0 // set(): 1, 2 -> true -// gas irOptimized: 103082 +// gas irOptimized: 103032 // gas legacy: 103126 // gas legacyOptimized: 102967 // getLength() -> 68 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_clear_storage.sol b/test/libsolidity/semanticTests/array/copying/array_copy_clear_storage.sol index 58b9f2021..031fcfab4 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_clear_storage.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_clear_storage.sol @@ -15,6 +15,6 @@ contract C { // compileViaYul: also // ---- // f() -> 0 -// gas irOptimized: 139564 +// gas irOptimized: 139474 // gas legacy: 138913 // gas legacyOptimized: 137448 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_including_array.sol b/test/libsolidity/semanticTests/array/copying/array_copy_including_array.sol index f53078e84..5ea1f2407 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_including_array.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_including_array.sol @@ -42,7 +42,7 @@ contract c { // gas legacyOptimized: 2258654 // storage: empty // clear() -> 0, 0 -// gas irOptimized: 1854203 +// gas irOptimized: 1854143 // gas legacy: 1727169 // gas legacyOptimized: 1698931 // storage: empty diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_dynamic_dynamic.sol b/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_dynamic_dynamic.sol index 4123cb9aa..fa2904c6a 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_dynamic_dynamic.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_dynamic_dynamic.sol @@ -20,6 +20,6 @@ contract c { // compileViaYul: also // ---- // test() -> 5, 4 -// gas irOptimized: 265166 +// gas irOptimized: 265174 // gas legacy: 264734 // gas legacyOptimized: 263160 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_static_dynamic.sol b/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_static_dynamic.sol index d5a925b65..db7ae7377 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_static_dynamic.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_static_dynamic.sol @@ -14,4 +14,4 @@ contract c { // compileViaYul: also // ---- // test() -> 9, 4 -// gas irOptimized: 99211 +// gas irOptimized: 99186 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_static_static.sol b/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_static_static.sol index e7cab4bde..d8b1ca1fb 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_static_static.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_static_static.sol @@ -18,6 +18,6 @@ contract c { // compileViaYul: also // ---- // test() -> 8, 0 -// gas irOptimized: 154843 +// gas irOptimized: 154793 // gas legacy: 153995 // gas legacyOptimized: 153403 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_struct.sol b/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_struct.sol index b43c1e2b1..e52f71a90 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_struct.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_struct.sol @@ -19,7 +19,7 @@ contract c { // compileViaYul: also // ---- // test() -> 4, 5 -// gas irOptimized: 259216 +// gas irOptimized: 258946 // gas legacy: 255936 // gas legacyOptimized: 254359 // storage: empty diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_target_simple_2.sol b/test/libsolidity/semanticTests/array/copying/array_copy_target_simple_2.sol index 2a96043ba..9f6f78398 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_target_simple_2.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_target_simple_2.sol @@ -21,6 +21,6 @@ contract c { // compileViaYul: also // ---- // test() -> 0x01000000000000000000000000000000000000000000000000, 0x02000000000000000000000000000000000000000000000000, 0x03000000000000000000000000000000000000000000000000, 0x04000000000000000000000000000000000000000000000000, 0x00 -// gas irOptimized: 263975 +// gas irOptimized: 263885 // gas legacy: 269681 // gas legacyOptimized: 268753 diff --git a/test/libsolidity/semanticTests/array/copying/array_nested_memory_to_storage.sol b/test/libsolidity/semanticTests/array/copying/array_nested_memory_to_storage.sol index 9d5b78ea8..09bfac30a 100644 --- a/test/libsolidity/semanticTests/array/copying/array_nested_memory_to_storage.sol +++ b/test/libsolidity/semanticTests/array/copying/array_nested_memory_to_storage.sol @@ -40,7 +40,7 @@ contract Test { // compileViaYul: also // ---- // test() -> 24 -// gas irOptimized: 216483 +// gas irOptimized: 216453 // gas legacy: 215533 // gas legacyOptimized: 214947 // test1() -> 3 diff --git a/test/libsolidity/semanticTests/array/copying/array_of_structs_containing_arrays_memory_to_storage.sol b/test/libsolidity/semanticTests/array/copying/array_of_structs_containing_arrays_memory_to_storage.sol index 06c2fab78..17e9498fb 100644 --- a/test/libsolidity/semanticTests/array/copying/array_of_structs_containing_arrays_memory_to_storage.sol +++ b/test/libsolidity/semanticTests/array/copying/array_of_structs_containing_arrays_memory_to_storage.sol @@ -26,4 +26,4 @@ contract C { // compileViaYul: true // ---- // f() -> 3, 3, 3, 1 -// gas irOptimized: 187616 +// gas irOptimized: 187586 diff --git a/test/libsolidity/semanticTests/array/dynamic_array_cleanup.sol b/test/libsolidity/semanticTests/array/dynamic_array_cleanup.sol index b0b5b54b8..f614d04ef 100644 --- a/test/libsolidity/semanticTests/array/dynamic_array_cleanup.sol +++ b/test/libsolidity/semanticTests/array/dynamic_array_cleanup.sol @@ -16,7 +16,7 @@ contract c { // ---- // storage: empty // fill() -> -// gas irOptimized: 535914 +// gas irOptimized: 535917 // gas legacy: 504373 // gas legacyOptimized: 499648 // storage: nonempty diff --git a/test/libsolidity/semanticTests/array/push/array_push_packed_array.sol b/test/libsolidity/semanticTests/array/push/array_push_packed_array.sol index 4ea0c2dc6..4e9d2af1c 100644 --- a/test/libsolidity/semanticTests/array/push/array_push_packed_array.sol +++ b/test/libsolidity/semanticTests/array/push/array_push_packed_array.sol @@ -16,6 +16,6 @@ contract c { // compileViaYul: also // ---- // test() -> 1, 2, 3, 4 -// gas irOptimized: 112060 +// gas irOptimized: 112009 // gas legacy: 107098 // gas legacyOptimized: 106362 diff --git a/test/libsolidity/semanticTests/array/push/array_push_struct.sol b/test/libsolidity/semanticTests/array/push/array_push_struct.sol index 828b5e7ee..167c07bfb 100644 --- a/test/libsolidity/semanticTests/array/push/array_push_struct.sol +++ b/test/libsolidity/semanticTests/array/push/array_push_struct.sol @@ -22,6 +22,6 @@ contract c { // compileViaYul: also // ---- // test() -> 2, 3, 4, 5 -// gas irOptimized: 146355 +// gas irOptimized: 146473 // gas legacy: 190684 // gas legacyOptimized: 188256 diff --git a/test/libsolidity/semanticTests/array/reusing_memory.sol b/test/libsolidity/semanticTests/array/reusing_memory.sol index b2199f7c7..1f43ae70e 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: 115557 +// gas irOptimized: 115537 // gas legacy: 127152 // gas legacyOptimized: 113679 diff --git a/test/libsolidity/semanticTests/externalContracts/snark.sol b/test/libsolidity/semanticTests/externalContracts/snark.sol index cf49f2b8d..6811f3e0d 100644 --- a/test/libsolidity/semanticTests/externalContracts/snark.sol +++ b/test/libsolidity/semanticTests/externalContracts/snark.sol @@ -296,6 +296,6 @@ contract Test { // g() -> true // pair() -> true // verifyTx() -> true -// gas irOptimized: 129895 +// gas irOptimized: 127891 // gas legacy: 130571 // gas legacyOptimized: 100147 diff --git a/test/libsolidity/semanticTests/functionCall/mapping_array_internal_argument.sol b/test/libsolidity/semanticTests/functionCall/mapping_array_internal_argument.sol index 9696d0d5f..e0794cede 100644 --- a/test/libsolidity/semanticTests/functionCall/mapping_array_internal_argument.sol +++ b/test/libsolidity/semanticTests/functionCall/mapping_array_internal_argument.sol @@ -20,7 +20,7 @@ contract test { // compileViaYul: also // ---- // set(uint8,uint8,uint8,uint8,uint8): 1, 21, 22, 42, 43 -> 0, 0, 0, 0 -// gas irOptimized: 110002 +// gas irOptimized: 109912 // gas legacy: 111406 // gas legacyOptimized: 107981 // get(uint8): 1 -> 21, 22, 42, 43 diff --git a/test/libsolidity/semanticTests/functionTypes/store_function.sol b/test/libsolidity/semanticTests/functionTypes/store_function.sol index 08ee1878d..d6e6cac75 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: 108993 +// gas irOptimized: 103930 // gas legacy: 161097 // gas legacyOptimized: 111516 diff --git a/test/libsolidity/semanticTests/structs/memory_structs_nested_load.sol b/test/libsolidity/semanticTests/structs/memory_structs_nested_load.sol index 29e408992..0f25bab0d 100644 --- a/test/libsolidity/semanticTests/structs/memory_structs_nested_load.sol +++ b/test/libsolidity/semanticTests/structs/memory_structs_nested_load.sol @@ -68,7 +68,7 @@ contract Test { // compileViaYul: also // ---- // load() -> 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 -// gas irOptimized: 111532 +// gas irOptimized: 111580 // gas legacy: 113999 // gas legacyOptimized: 106281 // store() -> 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 diff --git a/test/libsolidity/semanticTests/structs/struct_delete_storage_nested_small.sol b/test/libsolidity/semanticTests/structs/struct_delete_storage_nested_small.sol index 372e2ce38..b74ad6fd7 100644 --- a/test/libsolidity/semanticTests/structs/struct_delete_storage_nested_small.sol +++ b/test/libsolidity/semanticTests/structs/struct_delete_storage_nested_small.sol @@ -33,4 +33,4 @@ contract C { // compileViaYul: true // ---- // f() -> 0, 0, 0 -// gas irOptimized: 124720 +// gas irOptimized: 124955 diff --git a/test/libsolidity/semanticTests/structs/struct_delete_storage_with_array.sol b/test/libsolidity/semanticTests/structs/struct_delete_storage_with_array.sol index 102cabb1b..f771b1962 100644 --- a/test/libsolidity/semanticTests/structs/struct_delete_storage_with_array.sol +++ b/test/libsolidity/semanticTests/structs/struct_delete_storage_with_array.sol @@ -44,7 +44,7 @@ contract C { // compileViaYul: also // ---- // f() -> -// gas irOptimized: 124036 +// gas irOptimized: 123095 // gas legacy: 126832 // gas legacyOptimized: 125500 // g() -> diff --git a/test/libsolidity/semanticTests/various/destructuring_assignment.sol b/test/libsolidity/semanticTests/various/destructuring_assignment.sol index 89f591731..447ff1a56 100644 --- a/test/libsolidity/semanticTests/various/destructuring_assignment.sol +++ b/test/libsolidity/semanticTests/various/destructuring_assignment.sol @@ -36,6 +36,6 @@ contract C { // compileViaYul: also // ---- // f(bytes): 0x20, 0x5, "abcde" -> 0 -// gas irOptimized: 241975 +// gas irOptimized: 241858 // gas legacy: 239258 // gas legacyOptimized: 238577 diff --git a/test/libsolidity/semanticTests/viaYul/array_memory_index_access.sol b/test/libsolidity/semanticTests/viaYul/array_memory_index_access.sol index 8ae104209..1ed094157 100644 --- a/test/libsolidity/semanticTests/viaYul/array_memory_index_access.sol +++ b/test/libsolidity/semanticTests/viaYul/array_memory_index_access.sol @@ -28,7 +28,7 @@ contract C { // index(uint256): 10 -> true // index(uint256): 20 -> true // index(uint256): 0xFF -> true -// gas irOptimized: 167382 +// gas irOptimized: 167357 // gas legacy: 248854 // gas legacyOptimized: 152638 // accessIndex(uint256,int256): 10, 1 -> 2 diff --git a/test/libsolidity/semanticTests/viaYul/array_storage_push_empty.sol b/test/libsolidity/semanticTests/viaYul/array_storage_push_empty.sol index 9403c5e38..4d6f2fbac 100644 --- a/test/libsolidity/semanticTests/viaYul/array_storage_push_empty.sol +++ b/test/libsolidity/semanticTests/viaYul/array_storage_push_empty.sol @@ -13,11 +13,11 @@ contract C { // compileViaYul: also // ---- // pushEmpty(uint256): 128 -// gas irOptimized: 635248 +// gas irOptimized: 629616 // gas legacy: 607287 // gas legacyOptimized: 589048 // pushEmpty(uint256): 256 -// gas irOptimized: 870384 +// gas irOptimized: 859120 // gas legacy: 828983 // gas legacyOptimized: 802808 // pushEmpty(uint256): 32768 -> FAILURE # out-of-gas # diff --git a/test/libyul/Metrics.cpp b/test/libyul/Metrics.cpp index e9a591b62..f8c5920f2 100644 --- a/test/libyul/Metrics.cpp +++ b/test/libyul/Metrics.cpp @@ -296,7 +296,7 @@ BOOST_AUTO_TEST_CASE(regular_for_loop) { BOOST_CHECK_EQUAL(codeSize( "{ for { let x := 0 } lt(x, 10) { x := add(x, 1) } { mstore(x, 1) } }" - ), 10); + ), 9); } BOOST_FIXTURE_TEST_CASE(regular_for_loop_custom_weights, CustomWeightFixture) @@ -307,7 +307,8 @@ BOOST_FIXTURE_TEST_CASE(regular_for_loop_custom_weights, CustomWeightFixture) 1 * m_weights.variableDeclarationCost + 1 * m_weights.assignmentCost + 3 * m_weights.functionCallCost + - 4 * m_weights.literalCost + + 3 * m_weights.literalCost + + 1 * m_weights.literalZeroCost + 3 * m_weights.identifierCost + 1 * m_weights.expressionStatementCost );