Add tests for ForLoopConditionIntoBody

This commit is contained in:
mingchuan 2019-05-18 13:36:29 +08:00
parent a86b00e8d0
commit 4ab377eb00
No known key found for this signature in database
GPG Key ID: 607CD25FA2D03651
6 changed files with 107 additions and 1 deletions

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();

View File

@ -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 }
// }
// }

View File

@ -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 }
// }
// }

View File

@ -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)
// }
// }

View File

@ -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)
// }
// }

View File

@ -40,6 +40,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>
@ -129,7 +130,7 @@ public:
}
cout << "(q)quit/(f)flatten/(c)se/initialize var(d)ecls/(x)plit/(j)oin/(g)rouper/(h)oister/" << endl;
cout << " (e)xpr inline/(i)nline/(s)implify/varname c(l)eaner/(u)nusedprune/ss(a) transform/" << endl;
cout << " (r)edundant assign elim./re(m)aterializer/f(o)r-loop-pre-rewriter/" << endl;
cout << " (r)edundant assign elim./re(m)aterializer/f(o)r-loop-init-rewriter/f(O)r-loop-condition-into-body/" << endl;
cout << " s(t)ructural simplifier/equi(v)alent function combiner/ssa re(V)erser/? " << endl;
cout << " co(n)trol flow simplifier/stack com(p)ressor/(D)ead code eliminator/? " << endl;
cout.flush();
@ -145,6 +146,9 @@ public:
case 'o':
ForLoopInitRewriter{}(*m_ast);
break;
case 'O':
ForLoopConditionIntoBody{}(*m_ast);
break;
case 'c':
(CommonSubexpressionEliminator{m_dialect})(*m_ast);
break;