[YulOpt] Implement loop-invariant code motion

This commit is contained in:
mingchuan
2019-11-28 11:59:29 +01:00
committed by chriseth
parent 7c063987c2
commit db60d123d0
22 changed files with 408 additions and 15 deletions
@@ -0,0 +1,23 @@
{
let b := 1
for { let a := 1 } iszero(eq(a, 10)) { a := add(a, 1) } {
let c := mload(3) // c cannot be moved because non-movable
let not_inv := add(b, c) // no_inv cannot be moved because its value depends on c
a := add(a, 1)
mstore(a, not_inv)
}
}
// ====
// step: loopInvariantCodeMotion
// ----
// {
// let b := 1
// let a := 1
// for { } iszero(eq(a, 10)) { a := add(a, 1) }
// {
// let c := mload(3)
// let not_inv := add(b, c)
// a := add(a, 1)
// mstore(a, not_inv)
// }
// }