Skip to content

mem2reg is performed in an incorrect block order #9771

@jfecher

Description

@jfecher

Aim

I was running into this in the alias graph refactor: for a given function:

acir(inline) fn main f0 {
  b0():
    v1 = allocate -> &mut Field
    store Field 0 at v1
    v3 = allocate -> &mut &mut Field
    store v1 at v3
    jmp b1(Field 0)
  b1(v0: Field):
    v4 = eq v0, Field 0
    jmpif v4 then: b2, else: b3
  b2():
    v12 = load v3 -> &mut Field
    store Field 2 at v12
    v14 = add v0, Field 1
    jmp b1(v14)
  b3():
    v5 = load v1 -> Field
    v7 = eq v5, Field 2
    constrain v5 == Field 2
    v8 = load v3 -> &mut Field
    v9 = load v3 -> &mut Field
    v10 = load v9 -> Field
    v11 = eq v10, Field 2
    constrain v10 == Field 2
    return
}

We iterate in reverse post order which is:

block order = [Id(0), Id(1), Id(3), Id(2)]

Notably, this has us analyzing b3 before its predecessor b2 is finished.

Expected Behavior

Barring loops, we should analyze all blocks only after their predecessor has finished being analyzed

Bug

We do not do this.

To Reproduce

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

No response

NoirJS Version

No response

Proving Backend Tooling & Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

Metadata

Metadata

Labels

bugSomething isn't workingssa

Type

No type

Projects

Status

📋 Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions