diff options
author | Dong-hee Na <donghee.na@python.org> | 2023-06-08 08:39:56 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-08 08:39:56 +0900 |
commit | aa5b762bd3a3e837678cf7f9e1434c0f68208a0e (patch) | |
tree | ffd19de4a3f175d02f812b12166b0568525e0c27 /Python/flowgraph.c | |
parent | ffeaec7e60c88d585deacb10264ba7a96e5e52df (diff) | |
download | cpython-aa5b762bd3a3e837678cf7f9e1434c0f68208a0e.tar.gz cpython-aa5b762bd3a3e837678cf7f9e1434c0f68208a0e.zip |
gh-104635: Eliminate redundant STORE_FAST instructions in the compiler (gh-105320)
Diffstat (limited to 'Python/flowgraph.c')
-rw-r--r-- | Python/flowgraph.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/Python/flowgraph.c b/Python/flowgraph.c index 2fd9a85b6d9..b16b508fe76 100644 --- a/Python/flowgraph.c +++ b/Python/flowgraph.c @@ -1515,15 +1515,18 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts) */ } break; + case STORE_FAST: + if (opcode == nextop && + oparg == bb->b_instr[i+1].i_oparg && + bb->b_instr[i].i_loc.lineno == bb->b_instr[i+1].i_loc.lineno) { + bb->b_instr[i].i_opcode = POP_TOP; + bb->b_instr[i].i_oparg = 0; + } + break; case SWAP: if (oparg == 1) { INSTR_SET_OP0(inst, NOP); - break; - } - if (swaptimize(bb, &i) < 0) { - goto error; } - apply_static_swaps(bb, i); break; case KW_NAMES: break; @@ -1538,6 +1541,16 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts) assert (!HAS_CONST(inst->i_opcode)); } } + + for (int i = 0; i < bb->b_iused; i++) { + cfg_instr *inst = &bb->b_instr[i]; + if (inst->i_opcode == SWAP) { + if (swaptimize(bb, &i) < 0) { + goto error; + } + apply_static_swaps(bb, i); + } + } return SUCCESS; error: return ERROR; |