Skip to content

Lifetime Management #47

Open
Open

Description

@ControlCplusControlV
No description provided.

Activity

  1. ControlCplusControlV commented on Dec 17, 2022

    @ControlCplusControlV
    OwnerAuthor

    Lifetime Management

    • If a variable is not going to be used after a given expression, no need to save it to memory.
    • If a variable is updated several times in a row, no need to save intermediate results to memory.

    Test Cases

    1. Input Yul
    {
        let a := 700
        let b := 100
        let c := 200
        let d := add(a, c)
    }
    
    
    1. Assembly Output
    
    // a gets pushed to the stack
    // b gets pushed to the stack
    // The stack is full, so the top value will attempt to save to memory
    //Since b is the top value, the optimizer will check if b is used later
    //if so, b gets saved to memory, if not, b gets dropped
    //then c gets pushed to the stack
    //a and c are added
    
    1. Input Yul
    let c = 1000
    let b = 15
    let a = 6
        
    let d = mul(a, b)
    let e = mul(d, a)
    
    1. Assembly Output
    // Assembly output should not put d back on the stack,
    //  because it is immediately used after, since in 
    //  multiplication the intermediate value 
    //  must be stored in memory.
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions