diff options
Diffstat (limited to 'test/libyul/yulOptimizerTests')
7 files changed, 301 insertions, 114 deletions
diff --git a/test/libyul/yulOptimizerTests/equivalentFunctionCombiner/multiple_complex.yul b/test/libyul/yulOptimizerTests/equivalentFunctionCombiner/multiple_complex.yul new file mode 100644 index 00000000..380f9f03 --- /dev/null +++ b/test/libyul/yulOptimizerTests/equivalentFunctionCombiner/multiple_complex.yul @@ -0,0 +1,114 @@ +{ + pop(f(1,2,3)) + pop(g(4,5,6)) + pop(h(7,8,9)) + function f(f1, f2, f3) -> rf + { + switch f1 + case 0 { + if f2 + { + rf := f3 + } + if not(f2) + { + rf := f1 + } + } + default { + rf := 3 + } + } + function g(g1, g2, g3) -> rg + { + switch g1 + case 0 { + if g2 + { + rg := g3 + } + if not(g2) + { + rg := g1 + } + } + default { + rg := 3 + } + } + function h(h1, h2, h3) -> rh + { + switch h1 + case 1 { + if h2 + { + rh := h3 + } + if not(h2) + { + rh := h1 + } + } + default { + rh := 3 + } + } +} +// ---- +// equivalentFunctionCombiner +// { +// pop(f(1, 2, 3)) +// pop(f(4, 5, 6)) +// pop(h(7, 8, 9)) +// function f(f1, f2, f3) -> rf +// { +// switch f1 +// case 0 { +// if f2 +// { +// rf := f3 +// } +// if not(f2) +// { +// rf := f1 +// } +// } +// default { +// rf := 3 +// } +// } +// function g(g1, g2, g3) -> rg +// { +// switch g1 +// case 0 { +// if g2 +// { +// rg := g3 +// } +// if not(g2) +// { +// rg := g1 +// } +// } +// default { +// rg := 3 +// } +// } +// function h(h1, h2, h3) -> rh +// { +// switch h1 +// case 1 { +// if h2 +// { +// rh := h3 +// } +// if not(h2) +// { +// rh := h1 +// } +// } +// default { +// rh := 3 +// } +// } +// } diff --git a/test/libyul/yulOptimizerTests/equivalentFunctionCombiner/simple.yul b/test/libyul/yulOptimizerTests/equivalentFunctionCombiner/simple.yul new file mode 100644 index 00000000..2d5b3ef8 --- /dev/null +++ b/test/libyul/yulOptimizerTests/equivalentFunctionCombiner/simple.yul @@ -0,0 +1,20 @@ +{ + f() + g() + function f() { mstore(1, mload(0)) } + function g() { mstore(1, mload(0)) } +} +// ---- +// equivalentFunctionCombiner +// { +// f() +// f() +// function f() +// { +// mstore(1, mload(0)) +// } +// function g() +// { +// mstore(1, mload(0)) +// } +// } diff --git a/test/libyul/yulOptimizerTests/equivalentFunctionCombiner/simple_different_vars.yul b/test/libyul/yulOptimizerTests/equivalentFunctionCombiner/simple_different_vars.yul new file mode 100644 index 00000000..d38a3d2e --- /dev/null +++ b/test/libyul/yulOptimizerTests/equivalentFunctionCombiner/simple_different_vars.yul @@ -0,0 +1,22 @@ +{ + pop(f()) + pop(g()) + function f() -> b { let a := mload(0) b := a } + function g() -> a { let b := mload(0) a := b } +} +// ---- +// equivalentFunctionCombiner +// { +// pop(f()) +// pop(f()) +// function f() -> b +// { +// let a := mload(0) +// b := a +// } +// function g() -> a_1 +// { +// let b_2 := mload(0) +// a_1 := b_2 +// } +// } diff --git a/test/libyul/yulOptimizerTests/equivalentFunctionCombiner/switch_case_order.yul b/test/libyul/yulOptimizerTests/equivalentFunctionCombiner/switch_case_order.yul new file mode 100644 index 00000000..4f3cad36 --- /dev/null +++ b/test/libyul/yulOptimizerTests/equivalentFunctionCombiner/switch_case_order.yul @@ -0,0 +1,32 @@ +{ + f(0) + g(1) + function f(x) { switch x case 0 { mstore(0, 42) } case 1 { mstore(1, 42) } } + function g(x) { switch x case 1 { mstore(1, 42) } case 0 { mstore(0, 42) } } +} +// ---- +// equivalentFunctionCombiner +// { +// f(0) +// f(1) +// function f(x) +// { +// switch x +// case 0 { +// mstore(0, 42) +// } +// case 1 { +// mstore(1, 42) +// } +// } +// function g(x_1) +// { +// switch x_1 +// case 1 { +// mstore(1, 42) +// } +// case 0 { +// mstore(0, 42) +// } +// } +// } diff --git a/test/libyul/yulOptimizerTests/fullSuite/abi2.yul b/test/libyul/yulOptimizerTests/fullSuite/abi2.yul index bb60b1fa..887399b6 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/abi2.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/abi2.yul @@ -1073,12 +1073,12 @@ // fullSuite // { // let _2 := mload(1) -// let _1042 := mload(0) -// if slt(sub(_2, _1042), 64) +// let _172 := mload(0) +// if slt(sub(_2, _172), 64) // { // revert(0, 0) // } -// sstore(0, and(calldataload(_1042), 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) +// sstore(0, and(calldataload(_172), 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) // let x0, x1, x2, x3, x4 := abi_decode_tuple_t_addresst_uint256t_bytes_calldata_ptrt_enum$_Operation_$1949(mload(7), mload(8)) // sstore(x1, x0) // sstore(x3, x2) @@ -1093,40 +1093,40 @@ // value0_57 := and(calldataload(add(headStart_55, value4)), 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) // value1_58 := calldataload(add(headStart_55, 32)) // let offset_62 := calldataload(add(headStart_55, 64)) -// let _1090 := 0xffffffffffffffff -// if gt(offset_62, _1090) +// let _220 := 0xffffffffffffffff +// if gt(offset_62, _220) // { // revert(value4, value4) // } -// let _1092 := add(headStart_55, offset_62) -// if iszero(slt(add(_1092, 0x1f), dataEnd_56)) +// let _222 := add(headStart_55, offset_62) +// if iszero(slt(add(_222, 0x1f), dataEnd_56)) // { // revert(value4, value4) // } -// let abi_decode_length_15_689 := calldataload(_1092) -// if gt(abi_decode_length_15_689, _1090) +// let abi_decode_length_15_116 := calldataload(_222) +// if gt(abi_decode_length_15_116, _220) // { // revert(value4, value4) // } -// if gt(add(add(_1092, abi_decode_length_15_689), 0x20), dataEnd_56) +// if gt(add(add(_222, abi_decode_length_15_116), 32), dataEnd_56) // { // revert(value4, value4) // } -// value2_59 := add(_1092, 0x20) -// value3 := abi_decode_length_15_689 -// let _1095 := calldataload(add(headStart_55, 96)) -// if iszero(lt(_1095, 3)) +// value2_59 := add(_222, 32) +// value3 := abi_decode_length_15_116 +// let _225 := calldataload(add(headStart_55, 96)) +// if iszero(lt(_225, 3)) // { // revert(value4, value4) // } -// value4 := _1095 +// value4 := _225 // } // function abi_encode_tuple_t_bytes32_t_address_t_uint256_t_bytes32_t_enum$_Operation_$1949_t_uint256_t_uint256_t_uint256_t_address_t_address_t_uint256__to_t_bytes32_t_address_t_uint256_t_bytes32_t_uint8_t_uint256_t_uint256_t_uint256_t_address_t_address_t_uint256_(headStart_252, value10_253, value9_254, value8_255, value7_256, value6_257, value5_258, value4_259, value3_260, value2_261, value1_262, value0_263) -> tail_264 // { // tail_264 := add(headStart_252, 352) // mstore(headStart_252, value0_263) -// let _1307 := 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -// mstore(add(headStart_252, 32), and(value1_262, _1307)) +// let _439 := 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF +// mstore(add(headStart_252, 32), and(value1_262, _439)) // mstore(add(headStart_252, 64), value2_261) // mstore(add(headStart_252, 96), value3_260) // if iszero(lt(value4_259, 3)) @@ -1137,8 +1137,8 @@ // mstore(add(headStart_252, 160), value5_258) // mstore(add(headStart_252, 192), value6_257) // mstore(add(headStart_252, 224), value7_256) -// mstore(add(headStart_252, 256), and(value8_255, _1307)) -// mstore(add(headStart_252, 288), and(value9_254, _1307)) +// mstore(add(headStart_252, 256), and(value8_255, _439)) +// mstore(add(headStart_252, 288), and(value9_254, _439)) // mstore(add(headStart_252, 320), value10_253) // } // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul b/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul index c909d39e..a8cac6c6 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul @@ -458,13 +458,14 @@ // ---- // fullSuite // { +// let _1 := 0x20 // let _2 := 0 -// let _485 := mload(_2) -// let abi_encode_pos := 0x20 -// let abi_encode_length_68 := mload(_485) -// mstore(0x20, abi_encode_length_68) +// let _268 := mload(_2) +// let abi_encode_pos := _1 +// let abi_encode_length_68 := mload(_268) +// mstore(_1, abi_encode_length_68) // abi_encode_pos := 64 -// let abi_encode_srcPtr := add(_485, 0x20) +// let abi_encode_srcPtr := add(_268, _1) // let abi_encode_i_69 := _2 // for { // } @@ -473,31 +474,45 @@ // abi_encode_i_69 := add(abi_encode_i_69, 1) // } // { -// abi_encode_t_array$_t_contract$_C_$55_$3_memory_to_t_array$_t_address_$3_memory_ptr(mload(abi_encode_srcPtr), abi_encode_pos) -// abi_encode_srcPtr := add(abi_encode_srcPtr, 0x20) +// let _668 := mload(abi_encode_srcPtr) +// let abi_encode_pos_71_760 := abi_encode_pos +// let abi_encode_srcPtr_73_762 := _668 +// let abi_encode_i_74_763 := _2 +// for { +// } +// lt(abi_encode_i_74_763, 0x3) +// { +// abi_encode_i_74_763 := add(abi_encode_i_74_763, 1) +// } +// { +// mstore(abi_encode_pos_71_760, and(mload(abi_encode_srcPtr_73_762), 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) +// abi_encode_srcPtr_73_762 := add(abi_encode_srcPtr_73_762, _1) +// abi_encode_pos_71_760 := add(abi_encode_pos_71_760, _1) +// } +// abi_encode_srcPtr := add(abi_encode_srcPtr, _1) // abi_encode_pos := add(abi_encode_pos, 0x60) // } -// let _487 := mload(0x40) -// let _488 := mload(0x20) -// if slt(sub(_487, _488), 128) +// let _270 := mload(64) +// let _271 := mload(_1) +// if slt(sub(_270, _271), 128) // { // revert(_2, _2) // } -// let abi_decode_offset_64 := calldataload(add(_488, 64)) -// let abi_decode__165 := 0xffffffffffffffff -// if gt(abi_decode_offset_64, abi_decode__165) +// let abi_decode_offset_64 := calldataload(add(_271, 64)) +// let abi_decode__74 := 0xffffffffffffffff +// if gt(abi_decode_offset_64, abi_decode__74) // { // revert(_2, _2) // } -// let abi_decode_value2_587 := abi_decode_t_array$_t_uint256_$dyn_memory_ptr(add(_488, abi_decode_offset_64), _487) -// let abi_decode_offset_65 := calldataload(add(_488, 96)) -// if gt(abi_decode_offset_65, abi_decode__165) +// let abi_decode_value2_367 := abi_decode_t_array$_t_uint256_$dyn_memory_ptr(add(_271, abi_decode_offset_64), _270) +// let abi_decode_offset_65 := calldataload(add(_271, 96)) +// if gt(abi_decode_offset_65, abi_decode__74) // { // revert(_2, _2) // } -// let abi_decode_value3_588 := abi_decode_t_array$_t_array$_t_uint256_$2_memory_$dyn_memory_ptr(add(_488, abi_decode_offset_65), _487) -// sstore(calldataload(_488), calldataload(add(_488, 32))) -// sstore(abi_decode_value2_587, abi_decode_value3_588) +// let abi_decode_value3_368 := abi_decode_t_array$_t_array$_t_uint256_$2_memory_$dyn_memory_ptr(add(_271, abi_decode_offset_65), _270) +// sstore(calldataload(_271), calldataload(add(_271, _1))) +// sstore(abi_decode_value2_367, abi_decode_value3_368) // sstore(_2, abi_encode_pos) // function abi_decode_t_array$_t_array$_t_uint256_$2_memory_$dyn_memory_ptr(offset_3, end_4) -> array_5 // { @@ -506,23 +521,19 @@ // revert(0, 0) // } // let length_6 := calldataload(offset_3) -// if gt(length_6, 0xffffffffffffffff) +// let array_5_115 := allocateMemory(array_allocation_size_t_array$_t_address_$dyn_memory(length_6)) +// array_5 := array_5_115 +// let dst_7 := array_5_115 +// mstore(array_5_115, length_6) +// let _16 := 0x20 +// dst_7 := add(array_5_115, _16) +// let src_8 := add(offset_3, _16) +// if gt(add(add(offset_3, mul(length_6, 0x40)), _16), end_4) // { // revert(0, 0) // } -// let array_allo__217 := 0x20 -// let array_5_254 := allocateMemory(add(mul(length_6, array_allo__217), array_allo__217)) -// array_5 := array_5_254 -// let dst_7 := array_5_254 -// mstore(array_5_254, length_6) -// dst_7 := add(array_5_254, array_allo__217) -// let src_8 := add(offset_3, array_allo__217) -// if gt(add(add(offset_3, mul(length_6, 0x40)), array_allo__217), end_4) -// { -// revert(0, 0) -// } -// let i_9_566 := 0 -// let i_9 := i_9_566 +// let i_9_346 := 0 +// let i_9 := i_9_346 // for { // } // lt(i_9, length_6) @@ -532,16 +543,17 @@ // { // if iszero(slt(add(src_8, 0x1f), end_4)) // { -// revert(i_9_566, i_9_566) +// revert(i_9_346, i_9_346) // } -// let abi_decode_array_13_263 := allocateMemory(array_allocation_size_t_array$_t_uint256_$2_memory(0x2)) -// let abi_decode_dst_15 := abi_decode_array_13_263 +// let abi_decode_array_13_124 := allocateMemory(array_allocation_size_t_array$_t_uint256_$2_memory(0x2)) +// let abi_decode_dst_15 := abi_decode_array_13_124 // let abi_decode_src_16 := src_8 -// if gt(add(src_8, 64), end_4) +// let abi_decode__289 := add(src_8, 0x40) +// if gt(abi_decode__289, end_4) // { -// revert(i_9_566, i_9_566) +// revert(i_9_346, i_9_346) // } -// let abi_decode_i_17 := i_9_566 +// let abi_decode_i_17 := i_9_346 // for { // } // lt(abi_decode_i_17, 0x2) @@ -550,12 +562,12 @@ // } // { // mstore(abi_decode_dst_15, calldataload(abi_decode_src_16)) -// abi_decode_dst_15 := add(abi_decode_dst_15, array_allo__217) -// abi_decode_src_16 := add(abi_decode_src_16, array_allo__217) +// abi_decode_dst_15 := add(abi_decode_dst_15, _16) +// abi_decode_src_16 := add(abi_decode_src_16, _16) // } -// mstore(dst_7, abi_decode_array_13_263) -// dst_7 := add(dst_7, array_allo__217) -// src_8 := add(src_8, 0x40) +// mstore(dst_7, abi_decode_array_13_124) +// dst_7 := add(dst_7, _16) +// src_8 := abi_decode__289 // } // } // function abi_decode_t_array$_t_uint256_$dyn_memory_ptr(offset_27, end_28) -> array_29 @@ -565,19 +577,14 @@ // revert(0, 0) // } // let length_30 := calldataload(offset_27) -// if gt(length_30, 0xffffffffffffffff) -// { -// revert(0, 0) -// } -// let array_allo__234 := 0x20 -// let array_allo__560 := mul(length_30, array_allo__234) -// let array_29_279 := allocateMemory(add(array_allo__560, array_allo__234)) -// array_29 := array_29_279 -// let dst_31 := array_29_279 -// mstore(array_29_279, length_30) -// dst_31 := add(array_29_279, array_allo__234) -// let src_32 := add(offset_27, array_allo__234) -// if gt(add(add(offset_27, array_allo__560), array_allo__234), end_28) +// let array_29_131 := allocateMemory(array_allocation_size_t_array$_t_address_$dyn_memory(length_30)) +// array_29 := array_29_131 +// let dst_31 := array_29_131 +// mstore(array_29_131, length_30) +// let _52 := 0x20 +// dst_31 := add(array_29_131, _52) +// let src_32 := add(offset_27, _52) +// if gt(add(add(offset_27, mul(length_30, _52)), _52), end_28) // { // revert(0, 0) // } @@ -590,36 +597,28 @@ // } // { // mstore(dst_31, calldataload(src_32)) -// dst_31 := add(dst_31, array_allo__234) -// src_32 := add(src_32, array_allo__234) +// dst_31 := add(dst_31, _52) +// src_32 := add(src_32, _52) // } // } -// function abi_encode_t_array$_t_contract$_C_$55_$3_memory_to_t_array$_t_address_$3_memory_ptr(value_70, pos_71) +// function allocateMemory(size) -> memPtr // { -// let srcPtr_73 := value_70 -// let i_74 := 0 -// for { -// } -// lt(i_74, 0x3) -// { -// i_74 := add(i_74, 1) -// } +// let memPtr_157 := mload(64) +// memPtr := memPtr_157 +// let newFreePtr := add(memPtr_157, size) +// if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr_157)) // { -// mstore(pos_71, and(mload(srcPtr_73), 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) -// srcPtr_73 := add(srcPtr_73, 0x20) -// pos_71 := add(pos_71, 0x20) +// revert(0, 0) // } +// mstore(64, newFreePtr) // } -// function allocateMemory(size) -> memPtr +// function array_allocation_size_t_array$_t_address_$dyn_memory(length_90) -> size_91 // { -// let memPtr_315 := mload(64) -// memPtr := memPtr_315 -// let newFreePtr := add(memPtr_315, size) -// if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr_315)) +// if gt(length_90, 0xffffffffffffffff) // { // revert(0, 0) // } -// mstore(64, newFreePtr) +// size_91 := add(mul(length_90, 0x20), 0x20) // } // function array_allocation_size_t_array$_t_uint256_$2_memory(length_94) -> size_95 // { diff --git a/test/libyul/yulOptimizerTests/fullSuite/aztec.yul b/test/libyul/yulOptimizerTests/fullSuite/aztec.yul index 4fcdaaf1..fc09b5d9 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/aztec.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/aztec.yul @@ -264,10 +264,10 @@ // } // { // let validateJo__34 := 0x20 -// let validateJo__376 := add(validateJo__10, mul(validateJo_i, 0xc0)) -// let validateJo_noteIndex := add(validateJo__376, 36) +// let validateJo__373 := add(validateJo__10, mul(validateJo_i, 0xc0)) +// let validateJo_noteIndex := add(validateJo__373, 0x24) // let validateJo_k := validateJo_i_290 -// let validateJo_a_292 := calldataload(add(validateJo__376, 68)) +// let validateJo_a_292 := calldataload(add(validateJo__373, 0x44)) // let validateJo_a := validateJo_a_292 // let validateJo_c := validateJo_challenge // let validateJo__39 := add(validateJo_i, 0x01) @@ -286,18 +286,18 @@ // switch gt(validateJo__39, validateJo_m) // case 1 { // validateJo_kn := addmod(validateJo_kn, sub(validateJo_gen_order, validateJo_k), validateJo_gen_order) -// let validateJo_x := mod(mload(0x00), validateJo_gen_order) +// let validateJo_x := mod(mload(validateJo_i_290), validateJo_gen_order) // validateJo_k := mulmod(validateJo_k, validateJo_x, validateJo_gen_order) // validateJo_a := mulmod(validateJo_a_292, validateJo_x, validateJo_gen_order) // validateJo_c := mulmod(validateJo_challenge, validateJo_x, validateJo_gen_order) -// mstore(0x00, keccak256(0x00, validateJo__34)) +// mstore(validateJo_i_290, keccak256(validateJo_i_290, validateJo__34)) // } // case 0 { // validateJo_kn := addmod(validateJo_kn, validateJo_k, validateJo_gen_order) // } // let validateJo__52 := 0x40 -// calldatacopy(0xe0, add(validateJo__376, 164), validateJo__52) -// calldatacopy(validateJo__34, add(validateJo__376, 100), validateJo__52) +// calldatacopy(0xe0, add(validateJo__373, 164), validateJo__52) +// calldatacopy(validateJo__34, add(validateJo__373, 100), validateJo__52) // let validateJo__61 := 0x120 // mstore(validateJo__61, sub(validateJo_gen_order, validateJo_c)) // let validateJo__62 := 0x60 @@ -329,8 +329,8 @@ // } // if iszero(validateJo_result) // { -// mstore(0x00, 400) -// revert(0x00, validateJo__34) +// mstore(validateJo_i_290, 400) +// revert(validateJo_i_290, validateJo__34) // } // validateJo_b := add(validateJo_b, validateJo__52) // } @@ -340,13 +340,13 @@ // } // if iszero(eq(mod(keccak256(validateJo__24, add(validateJo_b, 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd60)), validateJo_gen_order), validateJo_challenge)) // { -// mstore(0x00, 404) -// revert(0x00, 0x20) +// mstore(validateJo_i_290, 404) +// revert(validateJo_i_290, 0x20) // } -// mstore(0x00, 0x01) -// return(0x00, 0x20) -// mstore(0x00, 404) -// revert(0x00, 0x20) +// mstore(validateJo_i_290, 0x01) +// return(validateJo_i_290, 0x20) +// mstore(validateJo_i_290, 404) +// revert(validateJo_i_290, 0x20) // function validatePairing(t2) // { // let t2_x_1 := calldataload(t2) @@ -379,8 +379,8 @@ // let success := call(gas(), 8, 0, _165, _216, _165, _165) // if or(iszero(success), iszero(mload(_165))) // { -// mstore(0x00, 400) -// revert(0x00, _165) +// mstore(0, 400) +// revert(0, _165) // } // } // function validateCommitment(note, k_1, a_2) @@ -409,6 +409,6 @@ // { // calldatacopy(add(0x300, mul(i_7, 0x80)), add(add(notes_5, mul(i_7, 0xc0)), 0x60), 0x80) // } -// mstore(0x00, keccak256(0x300, mul(n_6, 0x80))) +// mstore(0, keccak256(0x300, mul(n_6, 0x80))) // } // } |