diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-06-17 15:07:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-17 15:07:20 (GMT) |
commit | 61a2229005749dac782fc2e950d3f4fd25ed2181 (patch) | |
tree | 09fc04b50bbf2c3de29bcc1f2a1a394f499bc9ee /Python/flowgraph.c | |
parent | 7c47f93dff878bdc43f5162dd878cbb375711570 (diff) | |
download | cpython-61a2229005749dac782fc2e950d3f4fd25ed2181.zip cpython-61a2229005749dac782fc2e950d3f4fd25ed2181.tar.gz cpython-61a2229005749dac782fc2e950d3f4fd25ed2181.tar.bz2 |
[3.13] gh-120367: fix removal of redundant NOPs and jumps after reordering hot-cold blocks (GH-120425) (#120621)
gh-120367: fix removal of redundant NOPs and jumps after reordering hot-cold blocks (GH-120425)
(cherry picked from commit 21866c8ed296524f0ca175c0f55b43744c2b30df)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Diffstat (limited to 'Python/flowgraph.c')
-rw-r--r-- | Python/flowgraph.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/Python/flowgraph.c b/Python/flowgraph.c index b43cb6b..17b62b6 100644 --- a/Python/flowgraph.c +++ b/Python/flowgraph.c @@ -1829,6 +1829,22 @@ error: static int resolve_line_numbers(cfg_builder *g, int firstlineno); +static int +remove_redundant_nops_and_jumps(cfg_builder *g) +{ + int removed_nops, removed_jumps; + do { + /* Convergence is guaranteed because the number of + * redundant jumps and nops only decreases. + */ + removed_nops = remove_redundant_nops(g); + RETURN_IF_ERROR(removed_nops); + removed_jumps = remove_redundant_jumps(g); + RETURN_IF_ERROR(removed_jumps); + } while(removed_nops + removed_jumps > 0); + return SUCCESS; +} + /* Perform optimizations on a control flow graph. The consts object should still be in list form to allow new constants to be appended. @@ -1850,17 +1866,7 @@ optimize_cfg(cfg_builder *g, PyObject *consts, PyObject *const_cache, int firstl } RETURN_IF_ERROR(remove_redundant_nops_and_pairs(g->g_entryblock)); RETURN_IF_ERROR(remove_unreachable(g->g_entryblock)); - - int removed_nops, removed_jumps; - do { - /* Convergence is guaranteed because the number of - * redundant jumps and nops only decreases. - */ - removed_nops = remove_redundant_nops(g); - RETURN_IF_ERROR(removed_nops); - removed_jumps = remove_redundant_jumps(g); - RETURN_IF_ERROR(removed_jumps); - } while(removed_nops + removed_jumps > 0); + RETURN_IF_ERROR(remove_redundant_nops_and_jumps(g)); assert(no_redundant_jumps(g)); return SUCCESS; } @@ -2330,7 +2336,7 @@ push_cold_blocks_to_end(cfg_builder *g) { b->b_next = cold_blocks; if (cold_blocks != NULL) { - RETURN_IF_ERROR(remove_redundant_jumps(g)); + RETURN_IF_ERROR(remove_redundant_nops_and_jumps(g)); } return SUCCESS; } |