Scribe icon indicating copy to clipboard operation
Scribe copied to clipboard

Constant Folding

Open ControlCplusControlV opened this issue 3 years ago • 1 comments

ControlCplusControlV avatar Dec 17 '22 22:12 ControlCplusControlV

Constant Folding

Evaluate all expressions which can be evaluated at compile time

    c := add(100, 15)
    a := add(c, 50)
    b := add(b, 10)

Should compiled down to a block which just PUSH's the result of 175 onto the stack.

Test Cases

  1. Input Yul
{
    let c:u32 := add(100, 15)
    let a:u32 := sub(c, 50)
    let b:u32 := mul(a, 10)
    let d:u32 := div(b, 2)
}
  1. Assembly Output
use.std::math::u256
 
begin
    # Assigning to d #
        # u32 literal 425 #
        push.425
end
  1. Input Yul
{
    let c := add(100, 15)
    let a := sub(c, 50)
    let b := mul(a, 10)
    let d := div(b, 2)
}
  1. Assembly Output
use.std::math::u256
 
 
begin
    # Assigning to d #
        # u256 literal: 425 #
        push.425        push.0          push.0          push.0          push.0          push.0          push.0          push.0         

end

ControlCplusControlV avatar Dec 17 '22 22:12 ControlCplusControlV