mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
gh-104635: Eliminate redundant STORE_FAST instructions in the compiler (gh-105320)
This commit is contained in:
parent
ffeaec7e60
commit
aa5b762bd3
4 changed files with 58 additions and 10 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue