YulOpt: Remove empty cases

This commit is contained in:
Mathias Baumann 2019-03-06 11:33:27 +01:00 committed by chriseth
parent be52aa3181
commit 21322dae29
6 changed files with 32 additions and 6 deletions

View File

@ -5,6 +5,9 @@ Language Features:
Compiler Features:
* SMTChecker: Support one-dimensional arrays.
* Yul Optimizer: Add rule to remove empty default switch cases
* Yul Optimizer: Add rule to remove empty cases if no default exists
* Yul Optimizer: Add rule to replace a switch with no cases with pop(expression)
Bugfixes:

View File

@ -28,6 +28,9 @@ namespace yul
* - replace if with empty body with pop(condition)
* - replace if with true condition with its body
* - remove if with false condition
* - remove empty default switch case
* - remove empty switch case if no default case exists
* - replace switch with no cases with pop(expression)
* - turn switch with single case into if
* - replace switch with only default case with pop(expression) and body
* - replace switch with const expr with matching case body
@ -49,6 +52,7 @@ private:
bool expressionAlwaysTrue(Expression const& _expression);
bool expressionAlwaysFalse(Expression const& _expression);
boost::optional<dev::u256> hasLiteralValue(Expression const& _expression) const;
boost::optional<std::vector<Statement>> reduceNoCaseSwitch(Switch& _switchStmt) const;
};
}

View File

@ -0,0 +1,19 @@
{
let y := 200
switch add(y, 4)
case 0 { }
case 1 { }
default { }
switch 4
case 0 { }
case 1 { }
default { }
}
// ----
// structuralSimplifier
// {
// let y := 200
// pop(add(y, 4))
// pop(4)
// }

View File

@ -8,8 +8,8 @@
// structuralSimplifier
// {
// let y := 200
// switch y
// case 1 {
// if eq(1, y)
// {
// y := 9
// }
// }

View File

@ -9,8 +9,8 @@
// structuralSimplifier
// {
// let y := 200
// switch y
// case 1 {
// if eq(1, y)
// {
// y := 9
// }
// }

View File

@ -8,8 +8,8 @@
// structuralSimplifier
// {
// let y := 200
// switch y
// case 1 {
// if eq(1, y)
// {
// y := 9
// }
// }