Skip to content

Use side effects of user-defined functions in other optimizer steps. #12091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 2, 2021

Conversation

chriseth
Copy link
Contributor

@chriseth chriseth commented Oct 5, 2021

No description provided.

@chriseth
Copy link
Contributor Author

chriseth commented Oct 5, 2021

I think it might really make sense to cache the side-effects in the context (same is true for the other side-effects as well).
If optimizer steps are semantically-equivalent transformations, then it should be OK to compute the side-effects once per optimizer loop iteration.

@chriseth chriseth force-pushed the controlFlowSideEffectsUserDefined branch 5 times, most recently from dbb304f to c33fd24 Compare October 11, 2021 12:48
@chriseth chriseth force-pushed the applyControlFlowSideEffectsUserDefined branch from aa07c7f to c2147b8 Compare October 11, 2021 15:51
@chriseth chriseth force-pushed the controlFlowSideEffectsUserDefined branch 3 times, most recently from 858bc30 to b0f9acf Compare October 13, 2021 10:09
@chriseth chriseth force-pushed the applyControlFlowSideEffectsUserDefined branch from c2147b8 to a904964 Compare October 13, 2021 15:40
@chriseth
Copy link
Contributor Author

Performance does not seem to be as big an issue as I thought.

@chriseth chriseth force-pushed the controlFlowSideEffectsUserDefined branch from 95b68f0 to 2c2269d Compare October 14, 2021 15:46
Base automatically changed from controlFlowSideEffectsUserDefined to develop October 14, 2021 16:28
@chriseth chriseth force-pushed the applyControlFlowSideEffectsUserDefined branch from a904964 to 3149036 Compare October 19, 2021 16:50
@bshastry
Copy link
Contributor

Fuzzer update:

There is a stack-use-after-scope here:

for (YulString callee: util::valueOrDefault(m_functionCalls, _function))

(see #10973 (comment) for discussion on a similar issue)

I am not sure if YulString as an rvalue reference temporary is the issue. At least one of similar issues in the past could be fixed by replacing temporary with a value on the stack. (see #11371)

@chriseth chriseth force-pushed the applyControlFlowSideEffectsUserDefined branch from 3149036 to 785e16f Compare October 25, 2021 14:36
@chriseth
Copy link
Contributor Author

Before merging this, some tests may need to be modified so that they are still purposeful.

@chriseth chriseth force-pushed the applyControlFlowSideEffectsUserDefined branch from 288de24 to c64e7d6 Compare October 25, 2021 16:00
@chriseth
Copy link
Contributor Author

Changed the tests to be meaningful, please double-check.

@chriseth
Copy link
Contributor Author

I think this could need some more tests in the relevant optimizer steps.

@chriseth chriseth force-pushed the applyControlFlowSideEffectsUserDefined branch 2 times, most recently from 8683dfb to 86294c4 Compare November 2, 2021 10:50
@chriseth chriseth force-pushed the applyControlFlowSideEffectsUserDefined branch from 245c277 to be6fb5f Compare November 2, 2021 10:59
holds_alternative<ExpressionStatement>(_statement) &&
isTerminatingBuiltin(std::get<ExpressionStatement>(_statement))
containsNonContinuingFunctionCall(std::get<ExpressionStatement>(_statement).expression)
)
return ControlFlow::Terminate;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that we need it right away, but in general it makes sense to distinguish between terminating and reverting here, doesn't it?

function f() { return(0,0) }
function g() { revert(0,0) }
{
  switch calldataload(0)
  case 0 {
    sstore(0, 0) // needs to stay
    f()
  }
  case 1 {
    sstore(0, 0) // can be removed
    g()
  }
}

Copy link
Member

@ekpyron ekpyron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming that the side effects are correct :-), this looks good!

I'm wondering if it's worth to catch this eventually:

for {} 1 {} {
  if g() { return(...) }
}
sstore(0, 1) // can be removed

but no need now in any case.

@chriseth chriseth merged commit a7b1378 into develop Nov 2, 2021
@chriseth chriseth deleted the applyControlFlowSideEffectsUserDefined branch November 2, 2021 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants