Skip to content

Commit

Permalink
opt LOAD_FAST LOAD_FAST SWAP
Browse files Browse the repository at this point in the history
  • Loading branch information
CCLDArjun committed Apr 6, 2023
1 parent 47753ec commit 22b6aff
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Python/flowgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,7 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts)
int opcode = 0;
int oparg = 0;
int nextop = 0;
int nextnextop = 0;
for (int i = 0; i < bb->b_iused; i++) {
cfg_instr *inst = &bb->b_instr[i];
bool is_copy_of_load_const = (opcode == LOAD_CONST &&
Expand All @@ -1383,8 +1384,19 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts)
}
}
nextop = i+1 < bb->b_iused ? bb->b_instr[i+1].i_opcode : 0;
nextnextop = i+2 < bb->b_iused ? bb->b_instr[i+2].i_opcode : 0;
assert(!IS_ASSEMBLER_OPCODE(opcode));
switch (opcode) {
case LOAD_FAST:
{
if (nextop == LOAD_FAST && nextnextop == SWAP && bb->b_instr[i+2].i_oparg == 2) {
cfg_instr tmp = *inst;
bb->b_instr[i] = bb->b_instr[i+1];
bb->b_instr[i+1] = tmp;
INSTR_SET_OP0(&bb->b_instr[i+2], NOP);
}
break;
}
/* Remove LOAD_CONST const; conditional jump */
case LOAD_CONST:
{
Expand Down

0 comments on commit 22b6aff

Please sign in to comment.