Re-implement unused assign / unused store eliminator.

This commit is contained in:
chriseth
2023-03-20 13:49:37 +01:00
parent 960889f532
commit fac5666dc9
13 changed files with 342 additions and 204 deletions
@@ -176,7 +176,7 @@ contract DepositContract is IDepositContract, ERC165 {
}
// ----
// constructor()
// gas irOptimized: 1430741
// gas irOptimized: 1419712
// gas legacy: 2427905
// gas legacyOptimized: 1773081
// supportsInterface(bytes4): 0x0 -> 0
@@ -0,0 +1,33 @@
{
function g() {
if calldataload(10) { revert(0, 0) }
}
function f() {
let a := calldataload(0)
if calldataload(1) {
// this can NOT be removed
a := 2
g()
}
sstore(0, a)
}
}
// ----
// step: unusedAssignEliminator
//
// {
// function g()
// {
// if calldataload(10) { revert(0, 0) }
// }
// function f()
// {
// let a := calldataload(0)
// if calldataload(1)
// {
// a := 2
// g()
// }
// sstore(0, a)
// }
// }
@@ -0,0 +1,22 @@
{
function f() {
let a := calldataload(0)
if calldataload(1) {
// this can be removed
a := 2
leave
}
sstore(0, a)
}
}
// ----
// step: unusedAssignEliminator
//
// {
// function f()
// {
// let a := calldataload(0)
// if calldataload(1) { leave }
// sstore(0, a)
// }
// }
@@ -0,0 +1,17 @@
{
let a := calldataload(0)
if calldataload(1) {
// this can be removed
a := 2
revert(0, 0)
}
sstore(0, a)
}
// ----
// step: unusedAssignEliminator
//
// {
// let a := calldataload(0)
// if calldataload(1) { revert(0, 0) }
// sstore(0, a)
// }
@@ -46,10 +46,7 @@
// for { } 1 { }
// {
// for { } 1 { a := 10 }
// {
// b := 12
// b := 11
// }
// { b := 11 }
// }
// }
// }
@@ -0,0 +1,35 @@
{
function g() -> x {
x := 7
if calldataload(0) {
x := 3
reverting()
}
if calldataload(1) {
x := 3
leave
}
x := 2
reverting()
}
function reverting() { revert(0, 0) }
sstore(0, g())
}
// ----
// step: unusedAssignEliminator
//
// {
// function g() -> x
// {
// if calldataload(0) { reverting() }
// if calldataload(1)
// {
// x := 3
// leave
// }
// reverting()
// }
// function reverting()
// { revert(0, 0) }
// sstore(0, g())
// }