Visitar URL original
compiler's eliminate_empty_basic_blocks does not remove empty block if it is the last in the compilation unit · Issue #95922 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20240106045338/https://github.com/python/cpython/issues/95922
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

compiler's eliminate_empty_basic_blocks does not remove empty block if it is the last in the compilation unit #95922

Closed
iritkatriel opened this issue Aug 12, 2022 · 3 comments · Fixed by #95924
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage

Comments

@iritkatriel
Copy link
Member

Because of the next->b_next in the loop condition, this does not remove an empty basic block at the end. I put an assert and saw that this can happen.

     for (basicblock *b = entryblock; b != NULL; b = b->b_next) {
         basicblock *next = b->b_next;
        if (next) {
            while (next->b_iused == 0 && next->b_next) {
                next = next->b_next;
            }
            b->b_next = next;
         }
     }
@iritkatriel iritkatriel added performance Performance or resource usage interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Aug 12, 2022
@iritkatriel iritkatriel self-assigned this Aug 12, 2022
iritkatriel added a commit to iritkatriel/cpython that referenced this issue Aug 12, 2022
@markshannon
Copy link
Member

If the last block is empty, then it must be unreachable. So is this a problem?

@iritkatriel
Copy link
Member Author

There probably isn't an actual problem in generated code, but it means we can't assume that there are no empty blocks in the b_next list, which we might be tempted to do, so it can create the kind of chaos that leads to bugs.

I found this through the new unit tests I'm writing, because the actual basicblocks didn't match the ones expected.

@iritkatriel
Copy link
Member Author

Empty blocks are not really a problem anywhere - they cause no code to be emitted, so we could not remove any of them.

iritkatriel added a commit that referenced this issue Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage
Projects
None yet
2 participants