Skip to content

bpo-42908: Eliminate NOPs in extended blocks. #24209

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -6328,10 +6328,9 @@ optimize_basic_block(basicblock *bb, PyObject *consts)


static void
clean_basic_block(basicblock *bb) {
/* Remove NOPs. */
clean_basic_block(basicblock *bb, int prev_lineno) {
/* Remove NOPs when legal to do so. */
int dest = 0;
int prev_lineno = -1;
for (int src = 0; src < bb->b_iused; src++) {
int lineno = bb->b_instr[src].i_lineno;
if (bb->b_instr[src].i_opcode == NOP) {
Expand Down Expand Up @@ -6531,7 +6530,7 @@ optimize_cfg(struct assembler *a, PyObject *consts)
if (optimize_basic_block(b, consts)) {
return -1;
}
clean_basic_block(b);
clean_basic_block(b, -1);
assert(b->b_predecessors == 0);
}
if (mark_reachable(a)) {
Expand All @@ -6544,6 +6543,15 @@ optimize_cfg(struct assembler *a, PyObject *consts)
b->b_nofallthrough = 0;
}
}
basicblock *pred = NULL;
for (basicblock *b = a->a_entry; b != NULL; b = b->b_next) {
int prev_lineno = -1;
if (pred && pred->b_iused) {
prev_lineno = pred->b_instr[pred->b_iused-1].i_lineno;
}
clean_basic_block(b, prev_lineno);
pred = b->b_nofallthrough ? NULL : b;
}
eliminate_empty_basic_blocks(a->a_entry);
/* Delete jump instructions made redundant by previous step. If a non-empty
block ends with a jump instruction, check if the next non-empty block
Expand Down Expand Up @@ -6571,7 +6579,7 @@ optimize_cfg(struct assembler *a, PyObject *consts)
case JUMP_ABSOLUTE:
case JUMP_FORWARD:
b_last_instr->i_opcode = NOP;
clean_basic_block(b);
clean_basic_block(b, -1);
maybe_empty_blocks = 1;
break;
}
Expand Down