You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After flattening the control flow graph we end up with the instructions
// Here v0 and v1 are `array_a` and `array_b`
v7 = if v2 then v1 else if v5 then v0
v8 = array_get v7, index v3
This results in us merging two 1000 element arrays (performing 2000 array reads, merging these values into a new 1000 element array) and then performing a single read at whatever_index.
Ideally users would refactor their code to do single reads from the two arrays and then merge that single index, e.g.
let value = if is_b { array_b[whatever_index]}else{ array_a[whatever_index]};assert(value == 0);
We can perform this optimisation automatically however, we can recognise that we're performing an array read from the output of an IfElse instruction and pull out reads from the original arrays and generate a new IfElse for that single array element. We then get the SSA
v9 = array_get v0, index v3
v10 = array_get v1, index v3
v11 = if v2 then v9 else if v5 then v10
v7 = if v2 then v1 else if v5 then v0 // preserve original merged array in case used elsewhere.
Constant folding will prevent any extra gates being produced should v7 survive DIE.
The text was updated successfully, but these errors were encountered:
Consider the program
After flattening the control flow graph we end up with the instructions
This results in us merging two 1000 element arrays (performing 2000 array reads, merging these values into a new 1000 element array) and then performing a single read at
whatever_index
.Ideally users would refactor their code to do single reads from the two arrays and then merge that single index, e.g.
We can perform this optimisation automatically however, we can recognise that we're performing an array read from the output of an
IfElse
instruction and pull out reads from the original arrays and generate a newIfElse
for that single array element. We then get the SSAConstant folding will prevent any extra gates being produced should
v7
survive DIE.The text was updated successfully, but these errors were encountered: