gh-104635: Eliminate redundant STORE_FAST instructions in the compiler (gh-105320)

This commit is contained in:
Dong-hee Na 2023-06-08 08:39:56 +09:00 committed by GitHub
parent ffeaec7e60
commit aa5b762bd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 10 deletions

View file

@ -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;