Improve some Yul object and command line tests to avoid using pop() which can be optimized out

This commit is contained in:
Alex Beregszaszi 2020-12-11 16:09:09 +00:00 committed by Kamil Śliwak
parent 8a6a330d95
commit cd60ade472
4 changed files with 279 additions and 76 deletions

View File

@ -14,7 +14,7 @@ object "C_6" {
let selector := shift_right_224_unsigned(calldataload(0))
pop(selector)
}
pop(iszero(calldatasize()))
sstore(0, iszero(calldatasize()))
revert(0, 0)
}

View File

@ -16,6 +16,7 @@ object "C_6" {
{
mstore(64, 128)
pop(iszero(lt(calldatasize(), 4)))
sstore(0, iszero(calldatasize()))
revert(0, 0)
}
}
@ -24,7 +25,7 @@ object "C_6" {
Binary representation:
60806040523415600f5760006000fd5b6010601d60003960106000f3fe608060405260043610155060006000fd
60806040523415600f5760006000fd5b6015601d60003960156000f3fe6080604052600436101550361560005560006000fd
Text representation:
/* "strict_asm_optimizer_steps/input.yul":45:48 */
@ -79,10 +80,18 @@ sub_0: assembly {
iszero
/* "strict_asm_optimizer_steps/input.yul":319:321 */
pop
/* "strict_asm_optimizer_steps/input.yul":570:571 */
/* "strict_asm_optimizer_steps/input.yul":533:547 */
calldatasize
/* "strict_asm_optimizer_steps/input.yul":526:548 */
iszero
/* "strict_asm_optimizer_steps/input.yul":523:524 */
0x00
/* "strict_asm_optimizer_steps/input.yul":567:568 */
/* "strict_asm_optimizer_steps/input.yul":516:549 */
sstore
/* "strict_asm_optimizer_steps/input.yul":576:577 */
0x00
/* "strict_asm_optimizer_steps/input.yul":560:572 */
/* "strict_asm_optimizer_steps/input.yul":573:574 */
0x00
/* "strict_asm_optimizer_steps/input.yul":566:578 */
revert
}

View File

@ -1,11 +1,16 @@
object "A" {
code {
pop(datasize("x"))
pop(datasize("C"))
let x := datasize("x")
let c := datasize("C")
sstore(0, x)
sstore(32, c)
}
object "B" {
code { pop(dataoffset("other")) }
code {
let o := dataoffset("other")
sstore(0, o)
}
data ".metadata" "M1"
data "other" "Hello, World2!"
}
@ -16,17 +21,38 @@ object "A" {
}
// ----
// Assembly:
// /* "source":26:44 */
// pop(0x0e)
// /* "source":49:67 */
// pop(0x03)
// 0x0e
// /* "source":26:48 */
// 0x03
// /* "source":90:91 */
// dup2
// /* "source":87:88 */
// 0x00
// /* "source":80:92 */
// sstore
// /* "source":108:109 */
// dup1
// /* "source":104:106 */
// 0x20
// /* "source":97:110 */
// sstore
// /* "source":20:114 */
// pop
// pop
// stop
// data_211450822d7f8c345093893187e7e1fbebc4ec67af72601920194be14104e336 48656c6c6f2c20576f726c643221
// data_e1629b9dda060bb30c7908346f6af189c16773fa148d3366701fbaa35d54f3c8 414243
//
// sub_0: assembly {
// /* "source":99:123 */
// pop(data_211450822d7f8c345093893187e7e1fbebc4ec67af72601920194be14104e336)
// data_211450822d7f8c345093893187e7e1fbebc4ec67af72601920194be14104e336
// /* "source":193:194 */
// dup1
// /* "source":190:191 */
// 0x00
// /* "source":183:195 */
// sstore
// /* "source":140:201 */
// pop
// stop
// data_211450822d7f8c345093893187e7e1fbebc4ec67af72601920194be14104e336 48656c6c6f2c20576f726c643221
//
@ -34,6 +60,6 @@ object "A" {
// }
//
// auxdata: 0x4d32
// Bytecode: 600e50600350fe4d32
// Opcodes: PUSH1 0xE POP PUSH1 0x3 POP INVALID 0x4D ORIGIN
// SourceMappings: 26:18:0:-:0;;49;
// Bytecode: 600e600381600055806020555050fe4d32
// Opcodes: PUSH1 0xE PUSH1 0x3 DUP2 PUSH1 0x0 SSTORE DUP1 PUSH1 0x20 SSTORE POP POP INVALID 0x4D ORIGIN
// SourceMappings: :::-:0;26:22:0;90:1;87;80:12;108:1;104:2;97:13;20:94;

View File

@ -1,32 +1,56 @@
object "A" {
code {
pop(dataoffset("A"))
pop(datasize("A"))
pop(dataoffset("B"))
pop(datasize("B"))
pop(dataoffset("B.C"))
pop(datasize("B.C"))
pop(dataoffset("B.E"))
pop(datasize("B.E"))
pop(dataoffset("B.C.D"))
pop(datasize("B.C.D"))
let a_o := dataoffset("A")
let a_s := datasize("A")
let b_o := dataoffset("B")
let b_s := datasize("B")
let bc_o := dataoffset("B.C")
let bc_s := datasize("B.C")
let be_o := dataoffset("B.E")
let be_s := datasize("B.E")
let bcd_o := dataoffset("B.C.D")
let bcd_s := datasize("B.C.D")
sstore(0, a_o)
sstore(32, a_s)
sstore(64, b_o)
sstore(96, b_s)
sstore(128, bc_o)
sstore(160, bc_s)
sstore(192, be_o)
sstore(224, be_s)
sstore(256, bcd_o)
sstore(288, bcd_s)
return(0, 320)
}
data "data1" "Hello, World!"
object "B" {
code {
pop(dataoffset("C"))
pop(datasize("C"))
pop(dataoffset("E"))
pop(datasize("E"))
pop(dataoffset("C.D"))
pop(datasize("C.D"))
let c_o := dataoffset("C")
let c_s := datasize("C")
let e_o := dataoffset("E")
let e_s := datasize("E")
let cd_o := dataoffset("C.D")
let cd_s := datasize("C.D")
sstore(0, c_o)
sstore(32, c_s)
sstore(64, e_o)
sstore(96, e_s)
sstore(128, cd_o)
sstore(160, cd_s)
return(0, 192)
}
object "C" {
code {
pop(dataoffset("D"))
pop(datasize("D"))
let d_o := dataoffset("D")
let d_s := datasize("D")
sstore(0, d_o)
sstore(32, d_s)
return(0, 64)
}
object "D" {
code {
@ -43,62 +67,206 @@ object "A" {
}
// ----
// Assembly:
// /* "source":26:46 */
// pop(0x00)
// /* "source":51:69 */
// pop(bytecodeSize)
// /* "source":74:94 */
// pop(dataOffset(sub_0))
// /* "source":99:117 */
// pop(dataSize(sub_0))
// /* "source":122:144 */
// pop(dataOffset(sub_0.sub_0))
// /* "source":149:169 */
// pop(dataSize(sub_0.sub_0))
// /* "source":174:196 */
// pop(dataOffset(sub_0.sub_1))
// /* "source":201:221 */
// pop(dataSize(sub_0.sub_1))
// /* "source":226:250 */
// pop(dataOffset(sub_0.sub_0.sub_0))
// /* "source":255:277 */
// pop(dataSize(sub_0.sub_0.sub_0))
// 0x00
// /* "source":26:52 */
// bytecodeSize
// /* "source":57:81 */
// dataOffset(sub_0)
// /* "source":86:112 */
// dataSize(sub_0)
// /* "source":117:141 */
// dataOffset(sub_0.sub_0)
// /* "source":146:175 */
// dataSize(sub_0.sub_0)
// /* "source":180:207 */
// dataOffset(sub_0.sub_1)
// /* "source":212:241 */
// dataSize(sub_0.sub_1)
// /* "source":246:273 */
// dataOffset(sub_0.sub_0.sub_0)
// /* "source":278:310 */
// dataSize(sub_0.sub_0.sub_0)
// /* "source":361:364 */
// dup10
// /* "source":358:359 */
// 0x00
// /* "source":351:365 */
// sstore
// /* "source":381:384 */
// dup9
// /* "source":377:379 */
// 0x20
// /* "source":370:385 */
// sstore
// /* "source":401:404 */
// dup8
// /* "source":397:399 */
// 0x40
// /* "source":390:405 */
// sstore
// /* "source":421:424 */
// dup7
// /* "source":417:419 */
// 0x60
// /* "source":410:425 */
// sstore
// /* "source":442:446 */
// dup6
// /* "source":437:440 */
// 0x80
// /* "source":430:447 */
// sstore
// /* "source":464:468 */
// dup5
// /* "source":459:462 */
// 0xa0
// /* "source":452:469 */
// sstore
// /* "source":486:490 */
// dup4
// /* "source":481:484 */
// 0xc0
// /* "source":474:491 */
// sstore
// /* "source":508:512 */
// dup3
// /* "source":503:506 */
// 0xe0
// /* "source":496:513 */
// sstore
// /* "source":530:535 */
// dup2
// /* "source":525:528 */
// 0x0100
// /* "source":518:536 */
// sstore
// /* "source":553:558 */
// dup1
// /* "source":548:551 */
// 0x0120
// /* "source":541:559 */
// sstore
// /* "source":574:577 */
// 0x0140
// /* "source":571:572 */
// 0x00
// /* "source":564:578 */
// return
// /* "source":20:582 */
// pop
// pop
// pop
// pop
// pop
// pop
// pop
// pop
// pop
// pop
// stop
// data_acaf3289d7b601cbd114fb36c4d29c85bbfd5e133f14cb355c3fd8d99367964f 48656c6c6f2c20576f726c6421
//
// sub_0: assembly {
// /* "source":347:367 */
// pop(dataOffset(sub_0))
// /* "source":374:392 */
// pop(dataSize(sub_0))
// /* "source":399:419 */
// pop(dataOffset(sub_1))
// /* "source":426:444 */
// pop(dataSize(sub_1))
// /* "source":451:473 */
// pop(dataOffset(sub_0.sub_0))
// /* "source":480:500 */
// pop(dataSize(sub_0.sub_0))
// dataOffset(sub_0)
// /* "source":648:674 */
// dataSize(sub_0)
// /* "source":681:705 */
// dataOffset(sub_1)
// /* "source":712:738 */
// dataSize(sub_1)
// /* "source":745:769 */
// dataOffset(sub_0.sub_0)
// /* "source":776:805 */
// dataSize(sub_0.sub_0)
// /* "source":857:860 */
// dup6
// /* "source":854:855 */
// 0x00
// /* "source":847:861 */
// sstore
// /* "source":879:882 */
// dup5
// /* "source":875:877 */
// 0x20
// /* "source":868:883 */
// sstore
// /* "source":901:904 */
// dup4
// /* "source":897:899 */
// 0x40
// /* "source":890:905 */
// sstore
// /* "source":923:926 */
// dup3
// /* "source":919:921 */
// 0x60
// /* "source":912:927 */
// sstore
// /* "source":946:950 */
// dup2
// /* "source":941:944 */
// 0x80
// /* "source":934:951 */
// sstore
// /* "source":970:974 */
// dup1
// /* "source":965:968 */
// 0xa0
// /* "source":958:975 */
// sstore
// /* "source":992:995 */
// 0xc0
// /* "source":989:990 */
// 0x00
// /* "source":982:996 */
// return
// /* "source":640:1002 */
// pop
// pop
// pop
// pop
// pop
// pop
// stop
//
// sub_0: assembly {
// /* "source":545:565 */
// pop(dataOffset(sub_0))
// /* "source":574:592 */
// pop(dataSize(sub_0))
// dataOffset(sub_0)
// /* "source":1041:1067 */
// dataSize(sub_0)
// /* "source":1120:1123 */
// dup2
// /* "source":1117:1118 */
// 0x00
// /* "source":1110:1124 */
// sstore
// /* "source":1144:1147 */
// dup1
// /* "source":1140:1142 */
// 0x20
// /* "source":1133:1148 */
// sstore
// /* "source":1167:1169 */
// 0x40
// /* "source":1164:1165 */
// 0x00
// /* "source":1157:1170 */
// return
// /* "source":1031:1178 */
// pop
// pop
// stop
//
// sub_0: assembly {
// /* "source":645:654 */
// /* "source":1223:1232 */
// invalid
// }
// }
//
// sub_1: assembly {
// /* "source":717:726 */
// /* "source":1295:1304 */
// invalid
// }
// }
// Bytecode: 600050604650601f50601d50603e50600850603d50600150603c50600150fe601350600850601b50600150601c50600150fe600750600150fefefefefefe600750600150fefe
// Opcodes: PUSH1 0x0 POP PUSH1 0x46 POP PUSH1 0x1F POP PUSH1 0x1D POP PUSH1 0x3E POP PUSH1 0x8 POP PUSH1 0x3D POP PUSH1 0x1 POP PUSH1 0x3C POP PUSH1 0x1 POP INVALID PUSH1 0x13 POP PUSH1 0x8 POP PUSH1 0x1B POP PUSH1 0x1 POP PUSH1 0x1C POP PUSH1 0x1 POP INVALID PUSH1 0x7 POP PUSH1 0x1 POP INVALID INVALID INVALID INVALID INVALID INVALID PUSH1 0x7 POP PUSH1 0x1 POP INVALID INVALID
// SourceMappings: 26:20:0:-:0;;51:18;;74:20;;99:18;;122:22;;149:20;;174:22;;201:20;;226:24;;255:22;
// Bytecode: 600060ad604f604760986015609760016096600189600055886020558760405586606055856080558460a0558360c0558260e055816101005580610120556101406000f350505050505050505050fe60306015604560016046600185600055846020558360405582606055816080558060a05560c06000f3505050505050fe60146001816000558060205560406000f35050fefefefefefe60146001816000558060205560406000f35050fefe
// Opcodes: PUSH1 0x0 PUSH1 0xAD PUSH1 0x4F PUSH1 0x47 PUSH1 0x98 PUSH1 0x15 PUSH1 0x97 PUSH1 0x1 PUSH1 0x96 PUSH1 0x1 DUP10 PUSH1 0x0 SSTORE DUP9 PUSH1 0x20 SSTORE DUP8 PUSH1 0x40 SSTORE DUP7 PUSH1 0x60 SSTORE DUP6 PUSH1 0x80 SSTORE DUP5 PUSH1 0xA0 SSTORE DUP4 PUSH1 0xC0 SSTORE DUP3 PUSH1 0xE0 SSTORE DUP2 PUSH2 0x100 SSTORE DUP1 PUSH2 0x120 SSTORE PUSH2 0x140 PUSH1 0x0 RETURN POP POP POP POP POP POP POP POP POP POP INVALID PUSH1 0x30 PUSH1 0x15 PUSH1 0x45 PUSH1 0x1 PUSH1 0x46 PUSH1 0x1 DUP6 PUSH1 0x0 SSTORE DUP5 PUSH1 0x20 SSTORE DUP4 PUSH1 0x40 SSTORE DUP3 PUSH1 0x60 SSTORE DUP2 PUSH1 0x80 SSTORE DUP1 PUSH1 0xA0 SSTORE PUSH1 0xC0 PUSH1 0x0 RETURN POP POP POP POP POP POP INVALID PUSH1 0x14 PUSH1 0x1 DUP2 PUSH1 0x0 SSTORE DUP1 PUSH1 0x20 SSTORE PUSH1 0x40 PUSH1 0x0 RETURN POP POP INVALID INVALID INVALID INVALID INVALID INVALID PUSH1 0x14 PUSH1 0x1 DUP2 PUSH1 0x0 SSTORE DUP1 PUSH1 0x20 SSTORE PUSH1 0x40 PUSH1 0x0 RETURN POP POP INVALID INVALID
// SourceMappings: :::-:0;26:26:0;57:24;86:26;117:24;146:29;180:27;212:29;246:27;278:32;361:3;358:1;351:14;381:3;377:2;370:15;401:3;397:2;390:15;421:3;417:2;410:15;442:4;437:3;430:17;464:4;459:3;452:17;486:4;481:3;474:17;508:4;503:3;496:17;530:5;525:3;518:18;553:5;548:3;541:18;574:3;571:1;564:14;20:562;;;;;;;;;