From efbd3666a72b3664c6b5838554c00072934f77fd Mon Sep 17 00:00:00 2001 From: nishant-sachdeva Date: Thu, 15 Sep 2022 15:49:18 +0530 Subject: [PATCH] added optimization. shl comes out from being distributed over and --- libevmasm/RuleList.h | 11 ++++++-- test/formal/and_distributed_over_shl.py | 25 +++++++++++++++++++ .../struct/struct_storage_ptr.sol | 2 +- .../arrays_complex_from_and_to_storage.sol | 2 +- .../array/byte_array_transitional_2.sol | 2 +- .../copying/array_copy_cleanup_uint40.sol | 2 +- ...ay_copy_storage_storage_different_base.sol | 2 +- ..._storage_storage_different_base_nested.sol | 2 +- ...y_copy_storage_storage_dynamic_dynamic.sol | 2 +- .../array_copy_storage_to_memory_nested.sol | 2 +- .../copying/array_copy_target_leftover.sol | 2 +- .../copying/array_copy_target_simple.sol | 2 +- .../copying/array_copy_target_simple_2.sol | 2 +- ...ts_containing_arrays_memory_to_storage.sol | 2 +- ...nup_during_multi_element_per_slot_copy.sol | 2 +- .../copying/storage_memory_packed_dyn.sol | 2 +- .../array/delete/bytes_delete_element.sol | 2 +- .../array/dynamic_array_cleanup.sol | 2 +- .../array/dynamic_multi_array_cleanup.sol | 2 +- .../array/pop/array_pop_uint16_transition.sol | 2 +- .../array/pop/array_pop_uint24_transition.sol | 2 +- .../array/pop/byte_array_pop_copy_long.sol | 2 +- .../pop/byte_array_pop_long_storage_empty.sol | 2 +- ...ray_pop_long_storage_empty_garbage_ref.sol | 2 +- .../array/pop/byte_array_pop_masking_long.sol | 2 +- .../semanticTests/array/push/array_push.sol | 2 +- .../array/push/byte_array_push_transition.sol | 2 +- .../array/push/push_no_args_2d.sol | 4 +-- .../array/push/push_no_args_bytes.sol | 2 +- .../event_dynamic_nested_array_storage_v2.sol | 2 +- .../events/event_indexed_string.sol | 2 +- ...truct_delete_storage_with_arrays_small.sol | 2 +- .../various/destructuring_assignment.sol | 2 +- .../viaYul/array_storage_index_access.sol | 18 ++++++------- .../array_storage_index_zeroed_test.sol | 8 +++--- .../optimize_shl_over_and.yul | 15 +++++++++++ 36 files changed, 94 insertions(+), 47 deletions(-) create mode 100644 test/formal/and_distributed_over_shl.py create mode 100644 test/libyul/yulOptimizerTests/expressionSimplifier/optimize_shl_over_and.yul diff --git a/libevmasm/RuleList.h b/libevmasm/RuleList.h index 9b20d0f8b..34fe4992d 100644 --- a/libevmasm/RuleList.h +++ b/libevmasm/RuleList.h @@ -440,7 +440,8 @@ std::vector> simplificationRuleListPart7( Pattern B, Pattern, Pattern X, - Pattern Y + Pattern Y, + Pattern Z ) { using Word = typename Pattern::Word; @@ -629,6 +630,12 @@ std::vector> simplificationRuleListPart7( feasibilityFunction }); + rules.push_back({ + // AND(SHL(Z, X), SHL(Z, Y)) -> SHL(Z, AND(X, Y)) + Builtins::AND(Builtins::SHL(Z, X), Builtins::SHL(Z, Y)), + [=]() -> Pattern { return Builtins::SHL(Z, Builtins::AND(X, Y)); } + }); + rules.push_back({ Builtins::BYTE(A, Builtins::SHL(B, X)), [=]() -> Pattern { return Builtins::BYTE(A.d() + B.d() / 8, X); }, @@ -823,7 +830,7 @@ std::vector> simplificationRuleList( rules += simplificationRuleListPart4_5(A, B, C, W, X); rules += simplificationRuleListPart5(_evmVersion.has_value(), A, B, C, W, X); rules += simplificationRuleListPart6(A, B, C, W, X); - rules += simplificationRuleListPart7(A, B, C, W, X); + rules += simplificationRuleListPart7(A, B, C, W, X, Y); rules += simplificationRuleListPart8(A, B, C, W, X); if (_evmVersion.has_value()) diff --git a/test/formal/and_distributed_over_shl.py b/test/formal/and_distributed_over_shl.py new file mode 100644 index 000000000..ba1b379cf --- /dev/null +++ b/test/formal/and_distributed_over_shl.py @@ -0,0 +1,25 @@ +from opcodes import AND, SHL +from rule import Rule +from z3 import BitVec + +""" +Rule: +AND(SHL(Z,X), SHL(Z,Y)) -> SHL(Z, AND(X,Y)) +""" + +rule = Rule() + +n_bits = 128 + +# Input vars +X = BitVec('X', n_bits) +Y = BitVec('Y', n_bits) +Z = BitVec('Z', n_bits) + +# Non optimized result +nonopt = AND(SHL(Z,X), SHL(Z,Y)) + +# Optimized result +opt = SHL(Z, AND(X,Y)) + +rule.check(nonopt, opt) diff --git a/test/libsolidity/semanticTests/abiEncoderV1/struct/struct_storage_ptr.sol b/test/libsolidity/semanticTests/abiEncoderV1/struct/struct_storage_ptr.sol index a6d601412..fa62b4f77 100644 --- a/test/libsolidity/semanticTests/abiEncoderV1/struct/struct_storage_ptr.sol +++ b/test/libsolidity/semanticTests/abiEncoderV1/struct/struct_storage_ptr.sol @@ -24,6 +24,6 @@ contract C { // ---- // library: L // f() -> 8, 7, 1, 2, 7, 12 -// gas irOptimized: 166525 +// gas irOptimized: 166513 // gas legacy: 169347 // gas legacyOptimized: 167269 diff --git a/test/libsolidity/semanticTests/array/arrays_complex_from_and_to_storage.sol b/test/libsolidity/semanticTests/array/arrays_complex_from_and_to_storage.sol index 17243226f..ed54d0279 100644 --- a/test/libsolidity/semanticTests/array/arrays_complex_from_and_to_storage.sol +++ b/test/libsolidity/semanticTests/array/arrays_complex_from_and_to_storage.sol @@ -12,7 +12,7 @@ contract Test { } // ---- // set(uint24[3][]): 0x20, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12 -> 0x06 -// gas irOptimized: 186766 +// gas irOptimized: 186550 // gas legacy: 211149 // gas legacyOptimized: 206054 // data(uint256,uint256): 0x02, 0x02 -> 0x09 diff --git a/test/libsolidity/semanticTests/array/byte_array_transitional_2.sol b/test/libsolidity/semanticTests/array/byte_array_transitional_2.sol index fad9647ec..5fdaca65b 100644 --- a/test/libsolidity/semanticTests/array/byte_array_transitional_2.sol +++ b/test/libsolidity/semanticTests/array/byte_array_transitional_2.sol @@ -17,6 +17,6 @@ contract c { } // ---- // test() -> 0 -// gas irOptimized: 157200 +// gas irOptimized: 157188 // gas legacy: 188576 // gas legacyOptimized: 183333 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_cleanup_uint40.sol b/test/libsolidity/semanticTests/array/copying/array_copy_cleanup_uint40.sol index 915c0aeed..a6f805d00 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_cleanup_uint40.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_cleanup_uint40.sol @@ -46,6 +46,6 @@ contract C { } // ---- // f() -> true -// gas irOptimized: 146936 +// gas irOptimized: 146756 // gas legacy: 155961 // gas legacyOptimized: 153588 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_different_base.sol b/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_different_base.sol index a0e600d1a..92d750a6e 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_different_base.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_different_base.sol @@ -17,6 +17,6 @@ contract c { } // ---- // test() -> 5, 4 -// gas irOptimized: 225027 +// gas irOptimized: 224973 // gas legacy: 233801 // gas legacyOptimized: 232816 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_different_base_nested.sol b/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_different_base_nested.sol index 85a2f1905..ad7c08019 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_different_base_nested.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_different_base_nested.sol @@ -23,6 +23,6 @@ contract c { // compileToEwasm: also // ---- // test() -> 3, 4 -// gas irOptimized: 189690 +// gas irOptimized: 189516 // gas legacy: 215253 // gas legacyOptimized: 212341 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 c9ae2c0e6..6910fa80a 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 @@ -18,6 +18,6 @@ contract c { // ---- // test() -> 5, 4 -// gas irOptimized: 272950 +// gas irOptimized: 272893 // gas legacy: 270834 // gas legacyOptimized: 269960 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_storage_to_memory_nested.sol b/test/libsolidity/semanticTests/array/copying/array_copy_storage_to_memory_nested.sol index 0aa448e98..27f1a6aa0 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_storage_to_memory_nested.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_storage_to_memory_nested.sol @@ -15,6 +15,6 @@ contract C { } // ---- // f() -> 0x20, 2, 0x40, 0xa0, 2, 0, 1, 2, 2, 3 -// gas irOptimized: 161777 +// gas irOptimized: 161735 // gas legacy: 162278 // gas legacyOptimized: 159955 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_target_leftover.sol b/test/libsolidity/semanticTests/array/copying/array_copy_target_leftover.sol index f2d02ee57..0a4ac31da 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_target_leftover.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_target_leftover.sol @@ -19,6 +19,6 @@ contract c { // compileToEwasm: also // ---- // test() -> 0xffffffff, 0x0000000000000000000000000a00090008000700060005000400030002000100, 0x0000000000000000000000000000000000000000000000000000000000000000 -// gas irOptimized: 124910 +// gas irOptimized: 124640 // gas legacy: 187414 // gas legacyOptimized: 165659 diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_target_simple.sol b/test/libsolidity/semanticTests/array/copying/array_copy_target_simple.sol index 5c01bf219..bc89a904a 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_target_simple.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_target_simple.sol @@ -21,6 +21,6 @@ contract c { // compileToEwasm: also // ---- // test() -> 0x01000000000000000000000000000000000000000000000000, 0x02000000000000000000000000000000000000000000000000, 0x03000000000000000000000000000000000000000000000000, 0x04000000000000000000000000000000000000000000000000, 0x0 -// gas irOptimized: 293621 +// gas irOptimized: 293486 // gas legacy: 303626 // gas legacyOptimized: 301945 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 89e30b0d4..554d6b820 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 { // compileToEwasm: also // ---- // test() -> 0x01000000000000000000000000000000000000000000000000, 0x02000000000000000000000000000000000000000000000000, 0x03000000000000000000000000000000000000000000000000, 0x04000000000000000000000000000000000000000000000000, 0x00 -// gas irOptimized: 273177 +// gas irOptimized: 273093 // gas legacy: 276360 // gas legacyOptimized: 275411 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 6701862b2..031461056 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: 182237 +// gas irOptimized: 181997 diff --git a/test/libsolidity/semanticTests/array/copying/cleanup_during_multi_element_per_slot_copy.sol b/test/libsolidity/semanticTests/array/copying/cleanup_during_multi_element_per_slot_copy.sol index 999d49eaa..c2dda730d 100644 --- a/test/libsolidity/semanticTests/array/copying/cleanup_during_multi_element_per_slot_copy.sol +++ b/test/libsolidity/semanticTests/array/copying/cleanup_during_multi_element_per_slot_copy.sol @@ -16,7 +16,7 @@ contract C { } // ---- // constructor() -// gas irOptimized: 237351 +// gas irOptimized: 236265 // gas legacy: 221315 // gas legacyOptimized: 185247 // f() -> 0 diff --git a/test/libsolidity/semanticTests/array/copying/storage_memory_packed_dyn.sol b/test/libsolidity/semanticTests/array/copying/storage_memory_packed_dyn.sol index 7f3bf1798..8fed11241 100644 --- a/test/libsolidity/semanticTests/array/copying/storage_memory_packed_dyn.sol +++ b/test/libsolidity/semanticTests/array/copying/storage_memory_packed_dyn.sol @@ -13,6 +13,6 @@ contract C { } // ---- // f() -> 2, 3, 4 -// gas irOptimized: 110135 +// gas irOptimized: 109838 // gas legacy: 126350 // gas legacyOptimized: 120704 diff --git a/test/libsolidity/semanticTests/array/delete/bytes_delete_element.sol b/test/libsolidity/semanticTests/array/delete/bytes_delete_element.sol index 652854cb8..9aadf0db0 100644 --- a/test/libsolidity/semanticTests/array/delete/bytes_delete_element.sol +++ b/test/libsolidity/semanticTests/array/delete/bytes_delete_element.sol @@ -16,6 +16,6 @@ contract c { } // ---- // test1() -> true -// gas irOptimized: 207928 +// gas irOptimized: 206428 // gas legacy: 254905 // gas legacyOptimized: 247415 diff --git a/test/libsolidity/semanticTests/array/dynamic_array_cleanup.sol b/test/libsolidity/semanticTests/array/dynamic_array_cleanup.sol index 342d98a11..9d1b02b22 100644 --- a/test/libsolidity/semanticTests/array/dynamic_array_cleanup.sol +++ b/test/libsolidity/semanticTests/array/dynamic_array_cleanup.sol @@ -14,7 +14,7 @@ contract c { // ---- // storageEmpty -> 1 // fill() -> -// gas irOptimized: 519487 +// gas irOptimized: 519361 // gas legacy: 521584 // gas legacyOptimized: 517027 // storageEmpty -> 0 diff --git a/test/libsolidity/semanticTests/array/dynamic_multi_array_cleanup.sol b/test/libsolidity/semanticTests/array/dynamic_multi_array_cleanup.sol index 2e5d032d3..90957b0dd 100644 --- a/test/libsolidity/semanticTests/array/dynamic_multi_array_cleanup.sol +++ b/test/libsolidity/semanticTests/array/dynamic_multi_array_cleanup.sol @@ -16,7 +16,7 @@ contract c { // ---- // storageEmpty -> 1 // fill() -> 8 -// gas irOptimized: 123024 +// gas irOptimized: 123012 // gas legacy: 121756 // gas legacyOptimized: 120687 // storageEmpty -> 0 diff --git a/test/libsolidity/semanticTests/array/pop/array_pop_uint16_transition.sol b/test/libsolidity/semanticTests/array/pop/array_pop_uint16_transition.sol index 1b15ef84d..93075959d 100644 --- a/test/libsolidity/semanticTests/array/pop/array_pop_uint16_transition.sol +++ b/test/libsolidity/semanticTests/array/pop/array_pop_uint16_transition.sol @@ -18,7 +18,7 @@ contract c { } // ---- // test() -> 38, 28, 18 -// gas irOptimized: 186370 +// gas irOptimized: 185650 // gas legacy: 189492 // gas legacyOptimized: 178318 // storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/pop/array_pop_uint24_transition.sol b/test/libsolidity/semanticTests/array/pop/array_pop_uint24_transition.sol index ac52c4daf..fbfca89d9 100644 --- a/test/libsolidity/semanticTests/array/pop/array_pop_uint24_transition.sol +++ b/test/libsolidity/semanticTests/array/pop/array_pop_uint24_transition.sol @@ -18,7 +18,7 @@ contract c { } // ---- // test() -> 20, 10 -// gas irOptimized: 158020 +// gas irOptimized: 157570 // gas legacy: 159279 // gas legacyOptimized: 152937 // storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/pop/byte_array_pop_copy_long.sol b/test/libsolidity/semanticTests/array/pop/byte_array_pop_copy_long.sol index 931069dee..a5332cfd7 100644 --- a/test/libsolidity/semanticTests/array/pop/byte_array_pop_copy_long.sol +++ b/test/libsolidity/semanticTests/array/pop/byte_array_pop_copy_long.sol @@ -10,6 +10,6 @@ contract c { // ---- // test() -> 0x20, 29, 0x0303030303030303030303030303030303030303030303030303030303000000 -// gas irOptimized: 109310 +// gas irOptimized: 109301 // gas legacy: 126702 // gas legacyOptimized: 123422 diff --git a/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty.sol b/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty.sol index 3d25e354d..2bebf21c6 100644 --- a/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty.sol +++ b/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty.sol @@ -16,7 +16,7 @@ contract c { } // ---- // test() -> true -// gas irOptimized: 176111 +// gas irOptimized: 175619 // gas legacy: 224093 // gas legacyOptimized: 205152 // storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty_garbage_ref.sol b/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty_garbage_ref.sol index ccb4de6e1..42a91e7ed 100644 --- a/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty_garbage_ref.sol +++ b/test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty_garbage_ref.sol @@ -15,7 +15,7 @@ contract c { } // ---- // test() -> -// gas irOptimized: 142636 +// gas irOptimized: 142528 // gas legacy: 164430 // gas legacyOptimized: 158513 // storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/pop/byte_array_pop_masking_long.sol b/test/libsolidity/semanticTests/array/pop/byte_array_pop_masking_long.sol index 9f3884dae..095109a18 100644 --- a/test/libsolidity/semanticTests/array/pop/byte_array_pop_masking_long.sol +++ b/test/libsolidity/semanticTests/array/pop/byte_array_pop_masking_long.sol @@ -10,6 +10,6 @@ contract c { // ---- // test() -> 0x20, 33, 0x303030303030303030303030303030303030303030303030303030303030303, 0x0300000000000000000000000000000000000000000000000000000000000000 -// gas irOptimized: 108115 +// gas irOptimized: 108097 // gas legacy: 125584 // gas legacyOptimized: 122560 diff --git a/test/libsolidity/semanticTests/array/push/array_push.sol b/test/libsolidity/semanticTests/array/push/array_push.sol index e608c6bc1..18f20c021 100644 --- a/test/libsolidity/semanticTests/array/push/array_push.sol +++ b/test/libsolidity/semanticTests/array/push/array_push.sol @@ -16,6 +16,6 @@ contract c { } // ---- // test() -> 5, 4, 3, 3 -// gas irOptimized: 111448 +// gas irOptimized: 111406 // gas legacy: 111838 // gas legacyOptimized: 111128 diff --git a/test/libsolidity/semanticTests/array/push/byte_array_push_transition.sol b/test/libsolidity/semanticTests/array/push/byte_array_push_transition.sol index 896fa47d4..119e4ca28 100644 --- a/test/libsolidity/semanticTests/array/push/byte_array_push_transition.sol +++ b/test/libsolidity/semanticTests/array/push/byte_array_push_transition.sol @@ -15,6 +15,6 @@ contract c { } // ---- // test() -> 0 -// gas irOptimized: 174126 +// gas irOptimized: 173456 // gas legacy: 216790 // gas legacyOptimized: 204003 diff --git a/test/libsolidity/semanticTests/array/push/push_no_args_2d.sol b/test/libsolidity/semanticTests/array/push/push_no_args_2d.sol index c85d92a47..4938e6e45 100644 --- a/test/libsolidity/semanticTests/array/push/push_no_args_2d.sol +++ b/test/libsolidity/semanticTests/array/push/push_no_args_2d.sol @@ -27,14 +27,14 @@ contract C { // ---- // l() -> 0 // f(uint256,uint256): 42, 64 -> -// gas irOptimized: 112476 +// gas irOptimized: 112470 // gas legacy: 108105 // gas legacyOptimized: 101987 // l() -> 1 // ll(uint256): 0 -> 43 // a(uint256,uint256): 0, 42 -> 64 // f(uint256,uint256): 84, 128 -> -// gas irOptimized: 119064 +// gas irOptimized: 119058 // gas legacy: 110325 // gas legacyOptimized: 96331 // l() -> 2 diff --git a/test/libsolidity/semanticTests/array/push/push_no_args_bytes.sol b/test/libsolidity/semanticTests/array/push/push_no_args_bytes.sol index 602755845..dae522e57 100644 --- a/test/libsolidity/semanticTests/array/push/push_no_args_bytes.sol +++ b/test/libsolidity/semanticTests/array/push/push_no_args_bytes.sol @@ -21,7 +21,7 @@ contract C { // ---- // l() -> 0 // g(uint256): 70 -> -// gas irOptimized: 183584 +// gas irOptimized: 182534 // gas legacy: 183811 // gas legacyOptimized: 179218 // l() -> 70 diff --git a/test/libsolidity/semanticTests/events/event_dynamic_nested_array_storage_v2.sol b/test/libsolidity/semanticTests/events/event_dynamic_nested_array_storage_v2.sol index a625e3de3..442a5299a 100644 --- a/test/libsolidity/semanticTests/events/event_dynamic_nested_array_storage_v2.sol +++ b/test/libsolidity/semanticTests/events/event_dynamic_nested_array_storage_v2.sol @@ -15,6 +15,6 @@ contract C { // ---- // createEvent(uint256): 42 -> // ~ emit E(uint256[][]): 0x20, 0x02, 0x40, 0xa0, 0x02, 0x2a, 0x2b, 0x02, 0x2c, 0x2d -// gas irOptimized: 185142 +// gas irOptimized: 185118 // gas legacy: 187603 // gas legacyOptimized: 184566 diff --git a/test/libsolidity/semanticTests/events/event_indexed_string.sol b/test/libsolidity/semanticTests/events/event_indexed_string.sol index 08dd7ce66..aeaf20c75 100644 --- a/test/libsolidity/semanticTests/events/event_indexed_string.sol +++ b/test/libsolidity/semanticTests/events/event_indexed_string.sol @@ -17,6 +17,6 @@ contract C { // ---- // deposit() -> // ~ emit E(string,uint256[4]): #0xa7fb06bb999a5eb9aff9e0779953f4e1e4ce58044936c2f51c7fb879b85c08bd, #0xe755d8cc1a8cde16a2a31160dcd8017ac32d7e2f13215b29a23cdae40a78aa81 -// gas irOptimized: 333476 +// gas irOptimized: 332396 // gas legacy: 388679 // gas legacyOptimized: 374441 diff --git a/test/libsolidity/semanticTests/structs/struct_delete_storage_with_arrays_small.sol b/test/libsolidity/semanticTests/structs/struct_delete_storage_with_arrays_small.sol index d07d14dd6..2345fea3c 100644 --- a/test/libsolidity/semanticTests/structs/struct_delete_storage_with_arrays_small.sol +++ b/test/libsolidity/semanticTests/structs/struct_delete_storage_with_arrays_small.sol @@ -27,4 +27,4 @@ contract C { // compileViaYul: true // ---- // f() -> 0 -// gas irOptimized: 111594 +// gas irOptimized: 111570 diff --git a/test/libsolidity/semanticTests/various/destructuring_assignment.sol b/test/libsolidity/semanticTests/various/destructuring_assignment.sol index 4581cb2f2..59b468fce 100644 --- a/test/libsolidity/semanticTests/various/destructuring_assignment.sol +++ b/test/libsolidity/semanticTests/various/destructuring_assignment.sol @@ -34,6 +34,6 @@ contract C { // ---- // f(bytes): 0x20, 0x5, "abcde" -> 0 -// gas irOptimized: 241890 +// gas irOptimized: 241872 // gas legacy: 243341 // gas legacyOptimized: 242454 diff --git a/test/libsolidity/semanticTests/viaYul/array_storage_index_access.sol b/test/libsolidity/semanticTests/viaYul/array_storage_index_access.sol index 7df79912a..a0987895c 100644 --- a/test/libsolidity/semanticTests/viaYul/array_storage_index_access.sol +++ b/test/libsolidity/semanticTests/viaYul/array_storage_index_access.sol @@ -16,38 +16,38 @@ contract C { // ---- // test_indices(uint256): 1 -> // test_indices(uint256): 129 -> -// gas irOptimized: 3021484 +// gas irOptimized: 3020710 // gas legacy: 3071683 // gas legacyOptimized: 3014415 // test_indices(uint256): 5 -> -// gas irOptimized: 722540 +// gas irOptimized: 722510 // gas legacy: 719151 // gas legacyOptimized: 716139 // test_indices(uint256): 10 -> -// gas irOptimized: 158407 +// gas irOptimized: 158347 // gas legacy: 162657 // gas legacyOptimized: 158422 // test_indices(uint256): 15 -> -// gas irOptimized: 173467 +// gas irOptimized: 173377 // gas legacy: 179782 // gas legacyOptimized: 173727 // test_indices(uint256): 0xFF -> -// gas irOptimized: 5681652 +// gas irOptimized: 5680122 // gas legacy: 5780977 // gas legacyOptimized: 5668997 // test_indices(uint256): 1000 -> -// gas irOptimized: 18208919 +// gas irOptimized: 18202919 // gas legacy: 18602799 // gas legacyOptimized: 18179744 // test_indices(uint256): 129 -> -// gas irOptimized: 5198552 +// gas irOptimized: 5197778 // gas legacy: 5212013 // gas legacyOptimized: 5157889 // test_indices(uint256): 128 -> -// gas irOptimized: 417500 +// gas irOptimized: 416732 // gas legacy: 470568 // gas legacyOptimized: 423768 // test_indices(uint256): 1 -> -// gas irOptimized: 726968 +// gas irOptimized: 726962 // gas legacy: 721789 // gas legacyOptimized: 720209 diff --git a/test/libsolidity/semanticTests/viaYul/array_storage_index_zeroed_test.sol b/test/libsolidity/semanticTests/viaYul/array_storage_index_zeroed_test.sol index 3eb553fe9..8b90995d3 100644 --- a/test/libsolidity/semanticTests/viaYul/array_storage_index_zeroed_test.sol +++ b/test/libsolidity/semanticTests/viaYul/array_storage_index_zeroed_test.sol @@ -52,18 +52,18 @@ contract C { // ---- // test_zeroed_indicies(uint256): 1 -> // test_zeroed_indicies(uint256): 5 -> -// gas irOptimized: 165074 +// gas irOptimized: 165044 // gas legacy: 166201 // gas legacyOptimized: 163439 // test_zeroed_indicies(uint256): 10 -> -// gas irOptimized: 282677 +// gas irOptimized: 282617 // gas legacy: 285088 // gas legacyOptimized: 280012 // test_zeroed_indicies(uint256): 15 -> -// gas irOptimized: 405422 +// gas irOptimized: 405332 // gas legacy: 409138 // gas legacyOptimized: 401827 // test_zeroed_indicies(uint256): 0xFF -> -// gas irOptimized: 6404812 +// gas irOptimized: 6403282 // gas legacy: 6466233 // gas legacyOptimized: 6333077 diff --git a/test/libyul/yulOptimizerTests/expressionSimplifier/optimize_shl_over_and.yul b/test/libyul/yulOptimizerTests/expressionSimplifier/optimize_shl_over_and.yul new file mode 100644 index 000000000..27d1845f5 --- /dev/null +++ b/test/libyul/yulOptimizerTests/expressionSimplifier/optimize_shl_over_and.yul @@ -0,0 +1,15 @@ +{ + let x := calldataload(0) + let a := and(shl(x, 248), shl(x, 12)) + sstore(10, a) +} +// ==== +// EVMVersion: >byzantium +// ---- +// step: expressionSimplifier +// +// { +// { +// sstore(10, shl(calldataload(0), 8)) +// } +// }