Skip to content
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

perf bug[venom]: unlifted variables in mem2var #4296

Open
charles-cooper opened this issue Oct 13, 2024 · 7 comments
Open

perf bug[venom]: unlifted variables in mem2var #4296

charles-cooper opened this issue Oct 13, 2024 · 7 comments
Assignees
Labels
bug - bytecode performance bug affecting bytecode performance (not correctness) bug - venom bug in experimental venom pipeline

Comments

@charles-cooper
Copy link
Member

charles-cooper commented Oct 13, 2024

Version Information

  • vyper Version (output of vyper --version): 6606ded

What's your issue about?

examples of unlifted variables:

  • loop variable
@external
def loop(x: uint256) -> uint256:
    res: uint256 = 9
    for i: uint256 in range(res, bound=10):
        res = res + i
    return res

Screenshot from 2024-10-13 17-05-40

  • unlifted assignment
@external
def foo(x: uint256) -> uint256:
    t: uint256 = 5 // x
    return 6 // x

image

How can it be fixed?

Fill this in if you know how to fix it.

@charles-cooper charles-cooper added the bug - bytecode performance bug affecting bytecode performance (not correctness) label Oct 13, 2024
@harkal
Copy link
Collaborator

harkal commented Oct 14, 2024

Looks like the "transpiler" is not generating the appropriate allocas

@charles-cooper
Copy link
Member Author

hmm. we should probably make sure in the transpiler that allocas get inserted in the entry block.

@harkal
Copy link
Collaborator

harkal commented Oct 14, 2024

Looked into it. The alloca is fine. We need to do memory analysis to lift those mstores.

@charles-cooper
Copy link
Member Author

i think the check for all(use.opcode == "mstore") for use in uses check in mem2var is blocking the second example:

elif all([inst.opcode == "mstore" for inst in uses]):
return

@charles-cooper
Copy link
Member Author

this is blocking the first example, since the venom code contains a store of the alloca variable (%ret_ofst = %11):

elif all([inst.opcode in ["mstore", "mload", "return"] for inst in uses]):

@harkal
Copy link
Collaborator

harkal commented Oct 14, 2024

Right. But it is not safe to lift those atm, as it fails. If alloca's were super correct the "all mstores" should have not been a problem, but it probably not correct :/

@charles-cooper
Copy link
Member Author

Right. But it is not safe to lift those atm, as it fails. If alloca's were super correct the "all mstores" should have not been a problem, but it probably not correct :/

my diagnosis is:

  • the first two guards in mem2var protect the calling convention, they are overly conservative. we should be able to add analysis to check which mloads/mstores are part of the calling convention
  • ret_ofst should probably not be magical, let me look into this more

@charles-cooper charles-cooper added the bug - venom bug in experimental venom pipeline label Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug - bytecode performance bug affecting bytecode performance (not correctness) bug - venom bug in experimental venom pipeline
Projects
None yet
Development

No branches or pull requests

3 participants
@charles-cooper @harkal and others