diff options
4 files changed, 29 insertions, 1 deletions
diff --git a/libyul/optimiser/SSAValueTracker.cpp b/libyul/optimiser/SSAValueTracker.cpp index 35b29b04..ef96c379 100644 --- a/libyul/optimiser/SSAValueTracker.cpp +++ b/libyul/optimiser/SSAValueTracker.cpp @@ -37,7 +37,7 @@ void SSAValueTracker::operator()(VariableDeclaration const& _varDecl) { if (_varDecl.variables.size() == 1) setValue(_varDecl.variables.front().name, _varDecl.value.get()); - else + else if (!_varDecl.value) for (auto const& var: _varDecl.variables) setValue(var.name, nullptr); } diff --git a/libyul/optimiser/SSAValueTracker.h b/libyul/optimiser/SSAValueTracker.h index e182e013..efec2200 100644 --- a/libyul/optimiser/SSAValueTracker.h +++ b/libyul/optimiser/SSAValueTracker.h @@ -33,6 +33,8 @@ namespace yul * Class that walks the AST and stores the initial value of each variable * that is never assigned to. * + * Default value is represented as nullptr. + * * Prerequisite: Disambiguator */ class SSAValueTracker: public ASTWalker diff --git a/test/libyul/yulOptimizerTests/expressionSimplifier/assigned_vars_multi.yul b/test/libyul/yulOptimizerTests/expressionSimplifier/assigned_vars_multi.yul new file mode 100644 index 00000000..51f5df40 --- /dev/null +++ b/test/libyul/yulOptimizerTests/expressionSimplifier/assigned_vars_multi.yul @@ -0,0 +1,14 @@ +{ + function f() -> x, z {} + let c, d := f() + let y := add(d, add(c, 7)) +} +// ---- +// expressionSimplifier +// { +// function f() -> x, z +// { +// } +// let c, d := f() +// let y := add(add(d, c), 7) +// } diff --git a/test/libyul/yulOptimizerTests/expressionSimplifier/unassigend_vars_multi.yul b/test/libyul/yulOptimizerTests/expressionSimplifier/unassigend_vars_multi.yul new file mode 100644 index 00000000..8c1ad789 --- /dev/null +++ b/test/libyul/yulOptimizerTests/expressionSimplifier/unassigend_vars_multi.yul @@ -0,0 +1,12 @@ +// c & d can't be optimized as expression simplifier doesn't handle default +// values yet +{ + let c, d + let y := add(d, add(c, 7)) +} +// ---- +// expressionSimplifier +// { +// let c, d +// let y := add(add(d, c), 7) +// } |