mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #6208 from ethereum/simplifyConstantSwitchFirst
Simplify constant switch first
This commit is contained in:
@@ -180,6 +180,9 @@ void StructuralSimplifier::simplify(std::vector<yul::Statement>& _statements)
|
||||
return {};
|
||||
},
|
||||
[&](Switch& _switchStmt) -> OptionalStatements {
|
||||
if (boost::optional<u256> const constExprVal = hasLiteralValue(*_switchStmt.expression))
|
||||
return replaceConstArgSwitch(_switchStmt, constExprVal.get());
|
||||
|
||||
removeEmptyDefaultFromSwitch(_switchStmt);
|
||||
removeEmptyCasesFromSwitch(_switchStmt);
|
||||
|
||||
@@ -187,8 +190,6 @@ void StructuralSimplifier::simplify(std::vector<yul::Statement>& _statements)
|
||||
return reduceNoCaseSwitch(_switchStmt);
|
||||
else if (_switchStmt.cases.size() == 1)
|
||||
return reduceSingleCaseSwitch(_switchStmt);
|
||||
else if (boost::optional<u256> const constExprVal = hasLiteralValue(*_switchStmt.expression))
|
||||
return replaceConstArgSwitch(_switchStmt, constExprVal.get());
|
||||
|
||||
return {};
|
||||
},
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
case 1 { }
|
||||
default { }
|
||||
|
||||
switch 4
|
||||
switch mload(4)
|
||||
case 0 { }
|
||||
case 1 { }
|
||||
default { }
|
||||
@@ -15,5 +15,5 @@
|
||||
// {
|
||||
// let y := 200
|
||||
// pop(add(y, 4))
|
||||
// pop(4)
|
||||
// pop(mload(4))
|
||||
// }
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
{
|
||||
let y := 200
|
||||
switch y
|
||||
switch calldataload(0)
|
||||
case 0 { }
|
||||
case 1 { y := 9 }
|
||||
case 2 { y := 10 }
|
||||
}
|
||||
// ----
|
||||
// structuralSimplifier
|
||||
// {
|
||||
// let y := 200
|
||||
// if eq(1, y)
|
||||
// {
|
||||
// switch calldataload(0)
|
||||
// case 1 {
|
||||
// y := 9
|
||||
// }
|
||||
// case 2 {
|
||||
// y := 10
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
let y := 200
|
||||
switch y
|
||||
switch calldataload(0)
|
||||
case 0 { }
|
||||
case 1 { y := 9 }
|
||||
default { }
|
||||
@@ -9,7 +9,7 @@
|
||||
// structuralSimplifier
|
||||
// {
|
||||
// let y := 200
|
||||
// if eq(1, y)
|
||||
// if eq(1, calldataload(0))
|
||||
// {
|
||||
// y := 9
|
||||
// }
|
||||
|
||||
+7
-3
@@ -1,15 +1,19 @@
|
||||
{
|
||||
let y := 200
|
||||
switch y
|
||||
switch calldataload(0)
|
||||
case 1 { y := 9 }
|
||||
case 2 { y := 10 }
|
||||
default { }
|
||||
}
|
||||
// ----
|
||||
// structuralSimplifier
|
||||
// {
|
||||
// let y := 200
|
||||
// if eq(1, y)
|
||||
// {
|
||||
// switch calldataload(0)
|
||||
// case 1 {
|
||||
// y := 9
|
||||
// }
|
||||
// case 2 {
|
||||
// y := 10
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{
|
||||
switch 1 case 2 { mstore(0, 0) }
|
||||
switch calldataload(0) case 2 { mstore(0, 0) }
|
||||
}
|
||||
// ----
|
||||
// structuralSimplifier
|
||||
// {
|
||||
// if eq(2, 1)
|
||||
// if eq(2, calldataload(0))
|
||||
// {
|
||||
// mstore(0, 0)
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user