Merge pull request #6494 from sifmelcara/fix-dead-code-eliminator

Fix variable decl scope issue in DeadCodeEliminator
This commit is contained in:
Daniel Kirchner 2019-04-11 12:04:33 +02:00 committed by GitHub
commit 7e0c6234ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 24 additions and 7 deletions

View File

@ -38,6 +38,10 @@ namespace yul
* Function definitions are retained as they might be called by earlier
* code and thus are considered reachable.
*
* Because variables declared in a for loop's init block have their scope extended to the loop body,
* we require ForLoopInitRewriter to run before this step.
*
* Prerequisite: ForLoopInitRewriter
*/
class DeadCodeEliminator: public ASTModifier
{

View File

@ -71,11 +71,11 @@ void OptimiserSuite::run(
VarDeclInitializer{}(ast);
FunctionHoister{}(ast);
BlockFlattener{}(ast);
ForLoopInitRewriter{}(ast);
DeadCodeEliminator{}(ast);
FunctionGrouper{}(ast);
EquivalentFunctionCombiner::run(ast);
UnusedPruner::runUntilStabilised(*_dialect, ast, reservedIdentifiers);
ForLoopInitRewriter{}(ast);
BlockFlattener{}(ast);
StructuralSimplifier{*_dialect}(ast);
BlockFlattener{}(ast);

View File

@ -207,6 +207,7 @@ bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool con
else if (m_optimizerStep == "deadCodeEliminator")
{
disambiguate();
ForLoopInitRewriter{}(*m_ast);
DeadCodeEliminator{}(*m_ast);
}
else if (m_optimizerStep == "ssaTransform")

View File

@ -17,8 +17,8 @@
// step: deadCodeEliminator
// ----
// {
// let a := 20
// for {
// let a := 20
// }
// lt(a, 40)
// {

View File

@ -18,8 +18,8 @@
// step: deadCodeEliminator
// ----
// {
// let a := 20
// for {
// let a := 20
// }
// lt(a, 40)
// {

View File

@ -18,8 +18,8 @@
// step: deadCodeEliminator
// ----
// {
// let a := 20
// for {
// let a := 20
// }
// lt(a, 40)
// {

View File

@ -0,0 +1,12 @@
{
for { stop() let i_0 := 0 } lt(i_0,2) { i_0 := add(i_0,1) }
{
let i_1 := i_0
}
}
// ====
// step: deadCodeEliminator
// ----
// {
// stop()
// }

View File

@ -16,8 +16,8 @@
// step: deadCodeEliminator
// ----
// {
// let a := 20
// for {
// let a := 20
// }
// lt(a, 40)
// {

View File

@ -16,8 +16,8 @@
// step: deadCodeEliminator
// ----
// {
// let a := 20
// for {
// let a := 20
// }
// lt(a, 40)
// {

View File

@ -20,8 +20,8 @@
// ----
// {
// let b := 20
// let a := 20
// for {
// let a := 20
// }
// lt(a, 40)
// {