Merge pull request #6777 from sifmelcara/loop-cond-rewriter

[YulOpt] Implement ForLoopConditionIntoBody
This commit is contained in:
chriseth
2019-05-23 12:51:51 +02:00
committed by GitHub
10 changed files with 228 additions and 2 deletions
+6
View File
@@ -33,6 +33,7 @@
#include <libyul/optimiser/FunctionHoister.h>
#include <libyul/optimiser/ExpressionInliner.h>
#include <libyul/optimiser/FullInliner.h>
#include <libyul/optimiser/ForLoopConditionIntoBody.h>
#include <libyul/optimiser/ForLoopInitRewriter.h>
#include <libyul/optimiser/MainFunction.h>
#include <libyul/optimiser/Rematerialiser.h>
@@ -121,6 +122,11 @@ TestCase::TestResult YulOptimizerTest::run(ostream& _stream, string const& _line
VarDeclInitializer{}(*m_ast);
else if (m_optimizerStep == "varNameCleaner")
VarNameCleaner{*m_ast, *m_dialect}(*m_ast);
else if (m_optimizerStep == "forLoopConditionIntoBody")
{
disambiguate();
ForLoopConditionIntoBody{}(*m_ast);
}
else if (m_optimizerStep == "forLoopInitRewriter")
{
disambiguate();
@@ -0,0 +1,26 @@
{
let a := 1
for { } 42 { } { }
for { } "hello" { } { }
for { } 0 { } { }
for { } a { } { }
for { } add(a, a) { } { }
}
// ====
// step: forLoopConditionIntoBody
// ----
// {
// let a := 1
// for { } 42 { }
// { }
// for { } "hello" { }
// { }
// for { } 0 { }
// { }
// for { } 1 { }
// { if iszero(a) { break } }
// for { } 1 { }
// {
// if iszero(add(a, a)) { break }
// }
// }
@@ -0,0 +1,12 @@
{
for { let a := 1 } iszero(eq(a, 10)) { a := add(a, 1) } { }
}
// ====
// step: forLoopConditionIntoBody
// ----
// {
// for { let a := 1 } 1 { a := add(a, 1) }
// {
// if iszero(iszero(eq(a, 10))) { break }
// }
// }
@@ -0,0 +1,41 @@
{
let random := 42
for {
for { let a := 1} iszero(eq(a,10)) {} {
a := add(a, 1)
}
let b := 1
} iszero(eq(b, 10)) {
for { let c := 1 } iszero(eq(c,2)) { c := add(c, 1) } {
b := add(b, 1)
}
} {
mstore(b,b)
}
}
// ====
// step: forLoopConditionIntoBody
// ----
// {
// let random := 42
// for {
// for { let a := 1 } 1 { }
// {
// if iszero(iszero(eq(a, 10))) { break }
// a := add(a, 1)
// }
// let b := 1
// }
// 1
// {
// for { let c := 1 } 1 { c := add(c, 1) }
// {
// if iszero(iszero(eq(c, 2))) { break }
// b := add(b, 1)
// }
// }
// {
// if iszero(iszero(eq(b, 10))) { break }
// mstore(b, b)
// }
// }
@@ -0,0 +1,17 @@
{
let random := 42
for { let a := 1 } iszero(eq(a, 10)) { a := add(a, 1) } {
a := add(a, 1)
}
}
// ====
// step: forLoopConditionIntoBody
// ----
// {
// let random := 42
// for { let a := 1 } 1 { a := add(a, 1) }
// {
// if iszero(iszero(eq(a, 10))) { break }
// a := add(a, 1)
// }
// }