Add test case and adjust tests.

This commit is contained in:
Daniel Kirchner 2022-03-07 13:06:58 +01:00
parent ce0a3e93f2
commit 0a9d752b8b
12 changed files with 423 additions and 22 deletions

View File

@ -0,0 +1 @@
--experimental-via-ir --optimize --asm

View File

@ -0,0 +1,20 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >0.0.0;
contract C {
constructor(uint x) {
// In earlier versions of the compiler, the resulting assembly pushed the constant
// 0xFFFFFFFFFFFFFFFF42 directly in the subassembly of D, while it was optimized to
// ``sub(shl(0x48, 0x01), 0xbe)`` when C was compiled in isolation.
// Now the assembly is expected to contain two instances of ``sub(shl(0x48, 0x01), 0xbe)``,
// one in the creation code of ``C`` directly, one in a subassembly of ``D``.
// The constant 0xFFFFFFFFFFFFFFFF42 should not occur in the assembly output at all.
if (x == 0xFFFFFFFFFFFFFFFF42)
revert();
}
}
contract D {
function f() public pure returns (bytes memory) {
return type(C).creationCode;
}
}

View File

@ -0,0 +1,379 @@
======= viair_subobject_optimization/input.sol:C =======
EVM assembly:
/* "viair_subobject_optimization/input.sol":61:668 contract C {... */
0x80
dup1
0x40
mstore
jumpi(tag_6, callvalue)
0x1f
bytecodeSize
codesize
dup2
swap1
sub
swap2
dup3
add
not(0x1f)
and
dup4
add
swap2
sub(shl(0x40, 0x01), 0x01)
dup4
gt
dup5
dup5
lt
or
tag_4
jumpi
dup1
dup5
swap3
0x20
swap5
0x40
mstore
dup4
codecopy
dup2
add
sub
slt
tag_6
jumpi
tag_8
swap1
mload
tag_1
jump // in
tag_8:
mload(0x40)
dataSize(sub_0)
swap1
dup2
dataOffset(sub_0)
dup3
codecopy
return
tag_6:
pop
0x00
dup1
revert
tag_4:
pop
pop
pop
pop
mstore(0x00, shl(0xe0, 0x4e487b71))
mstore(0x04, 0x41)
revert(0x00, 0x24)
/* "viair_subobject_optimization/input.sol":76:666 constructor(uint x) {... */
tag_1:
sub(shl(0x48, 0x01), 0xbe)
/* "viair_subobject_optimization/input.sol":620:645 x == 0xFFFFFFFFFFFFFFFF42 */
eq
/* "viair_subobject_optimization/input.sol":616:661 if (x == 0xFFFFFFFFFFFFFFFF42)... */
tag_6
jumpi
/* "viair_subobject_optimization/input.sol":76:666 constructor(uint x) {... */
jump // out
stop
sub_0: assembly {
/* "viair_subobject_optimization/input.sol":61:668 contract C {... */
mstore(0x40, 0x80)
0x00
dup1
revert
auxdata: <AUXDATA REMOVED>
}
======= viair_subobject_optimization/input.sol:D =======
EVM assembly:
/* "viair_subobject_optimization/input.sol":669:772 contract D {... */
0x80
dup1
0x40
mstore
jumpi(tag_1, callvalue)
dataSize(sub_0)
swap1
dup2
dataOffset(sub_0)
dup3
codecopy
return
tag_1:
pop
0x00
dup1
revert
stop
sub_0: assembly {
/* "viair_subobject_optimization/input.sol":669:772 contract D {... */
0x80
dup1
0x40
mstore
jumpi(tag_2, iszero(lt(calldatasize, 0x04)))
tag_3:
pop
0x00
dup1
revert
tag_2:
0x00
swap1
dup2
calldataload
0xe0
shr
0x26121ff0
eq
tag_4
jumpi
pop
jump(tag_3)
tag_4:
jumpi(tag_8, callvalue)
dup2
add(calldatasize, not(0x03))
slt
tag_8
jumpi
/* "viair_subobject_optimization/input.sol":745:765 type(C).creationCode */
dataSize(sub_0)
/* "viair_subobject_optimization/input.sol":669:772 contract D {... */
0x3f
dup2
add
not(0x1f)
and
dup3
add
0xffffffffffffffff
dup2
gt
dup4
dup3
lt
or
tag_10
jumpi
tag_12
swap4
pop
0x40
mstore
/* "viair_subobject_optimization/input.sol":745:765 type(C).creationCode */
dup1
dup3
mstore
dataOffset(sub_0)
0x20
dup4
add
codecopy
/* "viair_subobject_optimization/input.sol":669:772 contract D {... */
mload(0x40)
swap2
dup3
swap2
dup3
tag_1
jump // in
tag_12:
sub
swap1
return
tag_10:
pop
pop
shl(0xe0, 0x4e487b71)
dup3
mstore
pop
mstore(0x04, 0x41)
0x24
swap1
revert
tag_8:
pop
dup1
revert
tag_1:
swap2
swap1
swap2
0x20
dup1
dup3
mstore
dup4
mload
swap1
dup2
dup2
dup5
add
mstore
0x00
swap5
tag_13:
dup3
dup7
lt
tag_14
jumpi
pop
pop
dup1
0x40
swap4
swap5
gt
tag_16
jumpi
tag_17:
0x1f
add
not(0x1f)
and
add
add
swap1
jump // out
tag_16:
0x00
dup4
dup3
dup5
add
add
mstore
jump(tag_17)
tag_14:
dup6
dup2
add
dup3
add
mload
dup5
dup8
add
0x40
add
mstore
swap5
dup2
add
swap5
jump(tag_13)
stop
sub_0: assembly {
/* "viair_subobject_optimization/input.sol":61:668 contract C {... */
0x80
dup1
0x40
mstore
jumpi(tag_6, callvalue)
0x1f
bytecodeSize
codesize
dup2
swap1
sub
swap2
dup3
add
not(0x1f)
and
dup4
add
swap2
sub(shl(0x40, 0x01), 0x01)
dup4
gt
dup5
dup5
lt
or
tag_4
jumpi
dup1
dup5
swap3
0x20
swap5
0x40
mstore
dup4
codecopy
dup2
add
sub
slt
tag_6
jumpi
tag_8
swap1
mload
tag_1
jump // in
tag_8:
mload(0x40)
dataSize(sub_0)
swap1
dup2
dataOffset(sub_0)
dup3
codecopy
return
tag_6:
pop
0x00
dup1
revert
tag_4:
pop
pop
pop
pop
mstore(0x00, shl(0xe0, 0x4e487b71))
mstore(0x04, 0x41)
revert(0x00, 0x24)
/* "viair_subobject_optimization/input.sol":76:666 constructor(uint x) {... */
tag_1:
sub(shl(0x48, 0x01), 0xbe)
/* "viair_subobject_optimization/input.sol":620:645 x == 0xFFFFFFFFFFFFFFFF42 */
eq
/* "viair_subobject_optimization/input.sol":616:661 if (x == 0xFFFFFFFFFFFFFFFF42)... */
tag_6
jumpi
/* "viair_subobject_optimization/input.sol":76:666 constructor(uint x) {... */
jump // out
stop
sub_0: assembly {
/* "viair_subobject_optimization/input.sol":61:668 contract C {... */
mstore(0x40, 0x80)
0x00
dup1
revert
auxdata: <AUXDATA REMOVED>
}
}
auxdata: <AUXDATA REMOVED>
}

View File

@ -1,10 +1,10 @@
object "RunsTest1" {
code {
// Deploy the contract
datacopy(0, dataoffset("Runtime"), datasize("Runtime"))
return(0, datasize("Runtime"))
datacopy(0, dataoffset("Runtime_deployed"), datasize("Runtime_deployed"))
return(0, datasize("Runtime_deployed"))
}
object "Runtime" {
object "Runtime_deployed" {
code {
let funcSel := shl(224, 0xabc12345)
sstore(0, funcSel)

View File

@ -5,12 +5,12 @@ Pretty printed source:
object "RunsTest1" {
code {
{
let _1 := datasize("Runtime")
datacopy(0, dataoffset("Runtime"), _1)
let _1 := datasize("Runtime_deployed")
datacopy(0, dataoffset("Runtime_deployed"), _1)
return(0, _1)
}
}
object "Runtime" {
object "Runtime_deployed" {
code {
{
sstore(0, 0xabc1234500000000000000000000000000000000000000000000000000000000)
@ -21,30 +21,31 @@ object "RunsTest1" {
Binary representation:
600c80600c6000396000f3fe63abc1234560e01b60005500
602580600c6000396000f3fe7fabc123450000000000000000000000000000000000000000000000000000000060005500
Text representation:
/* "yul_optimize_runs/input.yul":106:125 */
/* "yul_optimize_runs/input.yul":115:143 */
dataSize(sub_0)
/* "yul_optimize_runs/input.yul":83:104 */
/* "yul_optimize_runs/input.yul":83:113 */
dup1
dataOffset(sub_0)
/* "yul_optimize_runs/input.yul":80:81 */
0x00
/* "yul_optimize_runs/input.yul":71:126 */
/* "yul_optimize_runs/input.yul":71:144 */
codecopy
/* "yul_optimize_runs/input.yul":80:81 */
0x00
/* "yul_optimize_runs/input.yul":135:165 */
/* "yul_optimize_runs/input.yul":153:192 */
return
stop
sub_0: assembly {
shl(0xe0, 0xabc12345)
/* "yul_optimize_runs/input.yul":277:278 */
/* "yul_optimize_runs/input.yul":273:293 */
0xabc1234500000000000000000000000000000000000000000000000000000000
/* "yul_optimize_runs/input.yul":313:314 */
0x00
/* "yul_optimize_runs/input.yul":270:288 */
/* "yul_optimize_runs/input.yul":306:324 */
sstore
/* "yul_optimize_runs/input.yul":208:298 */
/* "yul_optimize_runs/input.yul":244:334 */
stop
}

View File

@ -26,6 +26,6 @@ contract Main {
// compileViaYul: also
// ----
// f(uint256): 0x34 -> 0x46bddb1178e94d7f2892ff5f366840eb658911794f2c3a44c450aa2c505186c1
// gas irOptimized: 113610
// gas irOptimized: 113613
// gas legacy: 126596
// gas legacyOptimized: 113823

View File

@ -26,6 +26,6 @@ contract Creator {
// compileViaYul: also
// ----
// f(uint256,address[]): 7, 0x40, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 -> 7, 8
// gas irOptimized: 444029
// gas irOptimized: 443989
// gas legacy: 590683
// gas legacyOptimized: 448326

View File

@ -26,6 +26,6 @@ contract Creator {
// compileViaYul: also
// ----
// f(uint256,bytes): 7, 0x40, 78, "abcdefghijklmnopqrstuvwxyzabcdef", "ghijklmnopqrstuvwxyzabcdefghijkl", "mnopqrstuvwxyz" -> 7, "h"
// gas irOptimized: 300885
// gas irOptimized: 300837
// gas legacy: 428917
// gas legacyOptimized: 298128

View File

@ -17,7 +17,7 @@ contract D {
// compileViaYul: also
// ----
// constructor(): 2 ->
// gas irOptimized: 203963
// gas irOptimized: 203982
// gas legacy: 245842
// gas legacyOptimized: 195676
// f() -> 2

View File

@ -18,7 +18,7 @@ contract D {
// compileViaYul: also
// ----
// constructor(): 2 ->
// gas irOptimized: 204126
// gas irOptimized: 204145
// gas legacy: 246202
// gas legacyOptimized: 195914
// f() -> 2

View File

@ -42,7 +42,7 @@ contract Main {
// compileViaYul: also
// ----
// constructor(), 22 wei ->
// gas irOptimized: 284283
// gas irOptimized: 284321
// gas legacy: 402045
// gas legacyOptimized: 266772
// getFlag() -> true

View File

@ -22,6 +22,6 @@ contract A {
// compileViaYul: also
// ----
// f(), 10 ether -> 3007, 3008, 3009
// gas irOptimized: 272449
// gas irOptimized: 272467
// gas legacy: 422501
// gas legacyOptimized: 287472