mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge remote-tracking branch 'origin/develop' into develop_060
This commit is contained in:
@@ -27,6 +27,8 @@
|
||||
#include <libyul/optimiser/DeadCodeEliminator.h>
|
||||
#include <libyul/optimiser/Disambiguator.h>
|
||||
#include <libyul/optimiser/CallGraphGenerator.h>
|
||||
#include <libyul/optimiser/ConditionalUnsimplifier.h>
|
||||
#include <libyul/optimiser/ConditionalSimplifier.h>
|
||||
#include <libyul/optimiser/CommonSubexpressionEliminator.h>
|
||||
#include <libyul/optimiser/NameCollector.h>
|
||||
#include <libyul/optimiser/EquivalentFunctionCombiner.h>
|
||||
@@ -157,6 +159,16 @@ TestCase::TestResult YulOptimizerTest::run(ostream& _stream, string const& _line
|
||||
disambiguate();
|
||||
CommonSubexpressionEliminator::run(*m_context, *m_ast);
|
||||
}
|
||||
else if (m_optimizerStep == "conditionalUnsimplifier")
|
||||
{
|
||||
disambiguate();
|
||||
ConditionalUnsimplifier::run(*m_context, *m_ast);
|
||||
}
|
||||
else if (m_optimizerStep == "conditionalSimplifier")
|
||||
{
|
||||
disambiguate();
|
||||
ConditionalSimplifier::run(*m_context, *m_ast);
|
||||
}
|
||||
else if (m_optimizerStep == "expressionSplitter")
|
||||
ExpressionSplitter::run(*m_context, *m_ast);
|
||||
else if (m_optimizerStep == "expressionJoiner")
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
let y := mload(0x20)
|
||||
for {} and(y, 8) { pop(y) } {
|
||||
if y { break }
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// step: conditionalSimplifier
|
||||
// ----
|
||||
// {
|
||||
// let y := mload(0x20)
|
||||
// for { } and(y, 8) { pop(y) }
|
||||
// {
|
||||
// if y { break }
|
||||
// y := 0
|
||||
// }
|
||||
// }
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
let y := mload(0x20)
|
||||
for {} and(y, 8) { pop(y) } {
|
||||
if y { continue }
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// step: conditionalSimplifier
|
||||
// ----
|
||||
// {
|
||||
// let y := mload(0x20)
|
||||
// for { } and(y, 8) { pop(y) }
|
||||
// {
|
||||
// if y { continue }
|
||||
// y := 0
|
||||
// }
|
||||
// }
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
let x := mload(0)
|
||||
let y := mload(0)
|
||||
if x { revert(0, 0) }
|
||||
if y { revert(0, 0) }
|
||||
for {} and(x, y) {} {
|
||||
x := 2
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// step: conditionalSimplifier
|
||||
// ----
|
||||
// {
|
||||
// let x := mload(0)
|
||||
// let y := mload(0)
|
||||
// if x { revert(0, 0) }
|
||||
// x := 0
|
||||
// if y { revert(0, 0) }
|
||||
// y := 0
|
||||
// for { } and(x, y) { }
|
||||
// { x := 2 }
|
||||
// }
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
let x
|
||||
for {} x { sstore(1, x) } {
|
||||
if x { continue }
|
||||
// x is 0 here, but should not be 0
|
||||
// anymore in the for loop post block
|
||||
sstore(0, x)
|
||||
}
|
||||
sstore(0, x)
|
||||
}
|
||||
// ====
|
||||
// step: conditionalSimplifier
|
||||
// ----
|
||||
// {
|
||||
// let x
|
||||
// for { } x { sstore(1, x) }
|
||||
// {
|
||||
// if x { continue }
|
||||
// x := 0
|
||||
// sstore(0, x)
|
||||
// }
|
||||
// sstore(0, x)
|
||||
// }
|
||||
@@ -0,0 +1,32 @@
|
||||
{
|
||||
let x := mload(0)
|
||||
for {} 1 {} {
|
||||
if x { sstore(7, 8) break sstore(8, 9) }
|
||||
sstore(1, x)
|
||||
if x { sstore(7, 8) break }
|
||||
sstore(10, x)
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// step: conditionalSimplifier
|
||||
// ----
|
||||
// {
|
||||
// let x := mload(0)
|
||||
// for { } 1 { }
|
||||
// {
|
||||
// if x
|
||||
// {
|
||||
// sstore(7, 8)
|
||||
// break
|
||||
// sstore(8, 9)
|
||||
// }
|
||||
// sstore(1, x)
|
||||
// if x
|
||||
// {
|
||||
// sstore(7, 8)
|
||||
// break
|
||||
// }
|
||||
// x := 0
|
||||
// sstore(10, x)
|
||||
// }
|
||||
// }
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
let x := mload(0)
|
||||
if x { sstore(0, x) }
|
||||
sstore(1, x)
|
||||
}
|
||||
// ====
|
||||
// step: conditionalSimplifier
|
||||
// ----
|
||||
// {
|
||||
// let x := mload(0)
|
||||
// if x { sstore(0, x) }
|
||||
// sstore(1, x)
|
||||
// }
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
let x := mload(0)
|
||||
if x { sstore(0, x) revert(0, 0) }
|
||||
sstore(1, x)
|
||||
}
|
||||
// ====
|
||||
// step: conditionalSimplifier
|
||||
// ----
|
||||
// {
|
||||
// let x := mload(0)
|
||||
// if x
|
||||
// {
|
||||
// sstore(0, x)
|
||||
// revert(0, 0)
|
||||
// }
|
||||
// x := 0
|
||||
// sstore(1, x)
|
||||
// }
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
let x := calldataload(0)
|
||||
switch x
|
||||
case 0 { }
|
||||
case 1 { }
|
||||
default { }
|
||||
|
||||
pop(x)
|
||||
}
|
||||
// ====
|
||||
// step: conditionalSimplifier
|
||||
// ----
|
||||
// {
|
||||
// let x := calldataload(0)
|
||||
// switch x
|
||||
// case 0 { x := 0 }
|
||||
// case 1 { x := 1 }
|
||||
// default { }
|
||||
// pop(x)
|
||||
// }
|
||||
@@ -0,0 +1,5 @@
|
||||
{ }
|
||||
// ====
|
||||
// step: conditionalSimplifier
|
||||
// ----
|
||||
// { }
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
let y := mload(0x20)
|
||||
for {} and(y, 8) { pop(y) } {
|
||||
if y { break }
|
||||
y := 0
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// step: conditionalUnsimplifier
|
||||
// ----
|
||||
// {
|
||||
// let y := mload(0x20)
|
||||
// for { } and(y, 8) { pop(y) }
|
||||
// { if y { break } }
|
||||
// }
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
let y := mload(0x20)
|
||||
for {} and(y, 8) { pop(y) } {
|
||||
if y { continue }
|
||||
y := 0
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// step: conditionalUnsimplifier
|
||||
// ----
|
||||
// {
|
||||
// let y := mload(0x20)
|
||||
// for { } and(y, 8) { pop(y) }
|
||||
// { if y { continue } }
|
||||
// }
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
let x := mload(0)
|
||||
let y := mload(0)
|
||||
if x { revert(0, 0) }
|
||||
x := 0
|
||||
if y { revert(0, 0) }
|
||||
y := 0
|
||||
for {} and(x, y) {} {
|
||||
x := 2
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// step: conditionalUnsimplifier
|
||||
// ----
|
||||
// {
|
||||
// let x := mload(0)
|
||||
// let y := mload(0)
|
||||
// if x { revert(0, 0) }
|
||||
// if y { revert(0, 0) }
|
||||
// for { } and(x, y) { }
|
||||
// { x := 2 }
|
||||
// }
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
let x
|
||||
for {} x { sstore(1, x) } {
|
||||
if x { continue }
|
||||
x := 0
|
||||
sstore(0, x)
|
||||
}
|
||||
sstore(0, x)
|
||||
}
|
||||
// ====
|
||||
// step: conditionalUnsimplifier
|
||||
// ----
|
||||
// {
|
||||
// let x
|
||||
// for { } x { sstore(1, x) }
|
||||
// {
|
||||
// if x { continue }
|
||||
// sstore(0, x)
|
||||
// }
|
||||
// sstore(0, x)
|
||||
// }
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
let x := mload(0)
|
||||
for {} 1 {} {
|
||||
if x { sstore(7, 8) break sstore(8, 9) }
|
||||
x := 0
|
||||
sstore(1, x)
|
||||
if x { sstore(7, 8) break }
|
||||
x := 0
|
||||
sstore(10, x)
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// step: conditionalUnsimplifier
|
||||
// ----
|
||||
// {
|
||||
// let x := mload(0)
|
||||
// for { } 1 { }
|
||||
// {
|
||||
// if x
|
||||
// {
|
||||
// sstore(7, 8)
|
||||
// break
|
||||
// sstore(8, 9)
|
||||
// }
|
||||
// x := 0
|
||||
// sstore(1, x)
|
||||
// if x
|
||||
// {
|
||||
// sstore(7, 8)
|
||||
// break
|
||||
// }
|
||||
// sstore(10, x)
|
||||
// }
|
||||
// }
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
let x := mload(0)
|
||||
if x { sstore(0, x) }
|
||||
x := 0
|
||||
sstore(1, x)
|
||||
}
|
||||
// ====
|
||||
// step: conditionalUnsimplifier
|
||||
// ----
|
||||
// {
|
||||
// let x := mload(0)
|
||||
// if x { sstore(0, x) }
|
||||
// x := 0
|
||||
// sstore(1, x)
|
||||
// }
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
let x := mload(0)
|
||||
if x { sstore(0, x) revert(0, 0) }
|
||||
x := 0
|
||||
sstore(1, x)
|
||||
}
|
||||
// ====
|
||||
// step: conditionalUnsimplifier
|
||||
// ----
|
||||
// {
|
||||
// let x := mload(0)
|
||||
// if x
|
||||
// {
|
||||
// sstore(0, x)
|
||||
// revert(0, 0)
|
||||
// }
|
||||
// sstore(1, x)
|
||||
// }
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
let x := calldataload(0)
|
||||
switch x
|
||||
case 0 { x := 0 }
|
||||
case 1 { x := 1 }
|
||||
case 2 { x := 8 /* wrong literal */ }
|
||||
default { }
|
||||
|
||||
pop(x)
|
||||
}
|
||||
// ====
|
||||
// step: conditionalUnsimplifier
|
||||
// ----
|
||||
// {
|
||||
// let x := calldataload(0)
|
||||
// switch x
|
||||
// case 0 { }
|
||||
// case 1 { }
|
||||
// case 2 { x := 8 }
|
||||
// default { }
|
||||
// pop(x)
|
||||
// }
|
||||
@@ -0,0 +1,5 @@
|
||||
{ }
|
||||
// ====
|
||||
// step: conditionalUnsimplifier
|
||||
// ----
|
||||
// { }
|
||||
@@ -17,8 +17,8 @@
|
||||
// { }
|
||||
// for { } 0 { }
|
||||
// { }
|
||||
// for { } 1 { }
|
||||
// { if iszero(a) { break } }
|
||||
// for { } a { }
|
||||
// { }
|
||||
// for { } 1 { }
|
||||
// {
|
||||
// if iszero(add(a, a)) { break }
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
let y := mload(0x20)
|
||||
for {} and(y, 8) { if y { revert(0, 0) } } {
|
||||
if y { continue }
|
||||
sstore(1, y)
|
||||
}
|
||||
if y { revert(0, 0) }
|
||||
}
|
||||
// ====
|
||||
// step: fullSuite
|
||||
// ----
|
||||
// {
|
||||
// {
|
||||
// let y := mload(0x20)
|
||||
// for { } and(y, 8) { if y { revert(0, 0) } }
|
||||
// {
|
||||
// if y { continue }
|
||||
// sstore(1, 0)
|
||||
// }
|
||||
// if y { revert(0, 0) }
|
||||
// }
|
||||
// }
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
sstore(0, array_sum(calldataload(0)))
|
||||
|
||||
function array_sum(x) -> sum {
|
||||
let length := calldataload(x)
|
||||
for { let i := 0 } lt(i, length) { i := add(i, 1) } {
|
||||
sum := add(sum, array_load(x, i))
|
||||
}
|
||||
}
|
||||
function array_load(x, i) -> v {
|
||||
let len := calldataload(x)
|
||||
if iszero(lt(i, len)) { revert(0, 0) }
|
||||
let data := add(x, 0x20)
|
||||
v := calldataload(add(data, mul(i, 0x20)))
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// step: fullSuite
|
||||
// ----
|
||||
// {
|
||||
// {
|
||||
// let _1 := calldataload(0)
|
||||
// let sum := 0
|
||||
// let i := sum
|
||||
// for { } lt(i, calldataload(_1)) { i := add(i, 1) }
|
||||
// {
|
||||
// sum := add(sum, calldataload(add(add(_1, mul(i, 0x20)), 0x20)))
|
||||
// }
|
||||
// sstore(0, sum)
|
||||
// }
|
||||
// }
|
||||
@@ -21,10 +21,10 @@
|
||||
// ----
|
||||
// {
|
||||
// {
|
||||
// let _1 := mload(0x40)
|
||||
// mstore(0x40, add(_1, 0x20))
|
||||
// mstore(0x40, add(_1, 96))
|
||||
// mstore(add(_1, 128), 2)
|
||||
// let p := mload(0x40)
|
||||
// mstore(0x40, add(p, 0x20))
|
||||
// mstore(0x40, add(p, 96))
|
||||
// mstore(add(p, 128), 2)
|
||||
// mstore(0x40, 0x20)
|
||||
// }
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user