Tests for conditional unsimplifier

This commit is contained in:
chriseth 2019-11-01 14:07:25 +01:00
parent ce87f11885
commit cca7f01199
10 changed files with 173 additions and 0 deletions

View File

@ -27,6 +27,7 @@
#include <libyul/optimiser/DeadCodeEliminator.h> #include <libyul/optimiser/DeadCodeEliminator.h>
#include <libyul/optimiser/Disambiguator.h> #include <libyul/optimiser/Disambiguator.h>
#include <libyul/optimiser/CallGraphGenerator.h> #include <libyul/optimiser/CallGraphGenerator.h>
#include <libyul/optimiser/ConditionalUnsimplifier.h>
#include <libyul/optimiser/ConditionalSimplifier.h> #include <libyul/optimiser/ConditionalSimplifier.h>
#include <libyul/optimiser/CommonSubexpressionEliminator.h> #include <libyul/optimiser/CommonSubexpressionEliminator.h>
#include <libyul/optimiser/NameCollector.h> #include <libyul/optimiser/NameCollector.h>
@ -158,6 +159,11 @@ TestCase::TestResult YulOptimizerTest::run(ostream& _stream, string const& _line
disambiguate(); disambiguate();
CommonSubexpressionEliminator::run(*m_context, *m_ast); CommonSubexpressionEliminator::run(*m_context, *m_ast);
} }
else if (m_optimizerStep == "conditionalUnsimplifier")
{
disambiguate();
ConditionalUnsimplifier::run(*m_context, *m_ast);
}
else if (m_optimizerStep == "conditionalSimplifier") else if (m_optimizerStep == "conditionalSimplifier")
{ {
disambiguate(); disambiguate();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,5 @@
{ }
// ====
// step: conditionalUnsimplifier
// ----
// { }