Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOM algorithm fails if there's a unreachable basic block #317

Open
chsasank opened this issue Apr 14, 2024 · 2 comments
Open

DOM algorithm fails if there's a unreachable basic block #317

chsasank opened this issue Apr 14, 2024 · 2 comments

Comments

@chsasank
Copy link

nodes = list(reversed(postorder(succ, entry))) # Reverse postorder.

Take this program for example (modified from interp test):

@print(n: int): int {
}
@main: int {
  v: int = const 4;
  jmp .somewhere;
  v: int = const 2;
.somewhere:
  tmp: int = call @print v;
  ret v;
}

Applying to_ssa creates this wrong output

@print(n: int): int {
}
@main: int {
.b1:
  v.0: int = const 4;
  jmp .somewhere;
.b2:
  v.1: int = const 2;
  jmp .somewhere;
.somewhere:
  tmp.0: int = phi __undefined tmp.1 .b1 .b2;
  tmp.1: int = call @print v.0;
  ret v.0;
}

Note the garbage phi instruction tmp.0. This happens because dominators are computed as follows in dom.py (which is then used by to_ssa.py)

{'b1': {'b1'}, 'b2': {'somewhere', 'b1'}, 'somewhere': {'somewhere', 'b1'}}

This is obviously wrong. This happens because get_dom algorithm fails when there's a node/basic block that doesn't have any predecessor that is not reachable from entry.

@chsasank
Copy link
Author

One solution is to ignore unreachable nodes. i,e modify this line

dom = {v: set(nodes) for v in succ}

to

    dom = {v: set(nodes) for v in nodes}

This creates issues with other algorithms

@chsasank
Copy link
Author

Sorry, I am wrong about above solution. This doesn't work. To fix my issue of accurate SSA transformation, I deleted basic blocks are not reachable. Here's my solution: chsasank/llama.lisp@7960abd#diff-bbd860f50f670b11d6286871f98a63200c8929d51b33d2c4b1cc1494f1f3687b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant