Module common_subexpression_elimination

Source
Expand description

The common subexpression elimination pass traverses the AST and removes duplicate definitions.

That is, this code:

function main(val: field) -> field {
    let x = val + 1field;
    let y = val + 1field;
    let z = x + y;
    return z;
}

Will be transformed to something like this:

function main(val: field) -> field {
    let x = val + 1field;
    let z = x + x;
    return z;
}

The pass expects flattening and destructuring to have already been run, and for the code to be in SSA form. Given that there is little flow control at this point in the compiler, there’s no need for any kind of data flow analysis.

Modules§

ast 🔒
program 🔒
visitor 🔒

Structs§

CommonSubexpressionEliminating