Index: Python/peephole.c =================================================================== --- Python/peephole.c (revision 56631) +++ Python/peephole.c (working copy) @@ -562,6 +562,20 @@ ISBASICBLOCK(blocks,i,4)) memset(codestr+i+1, NOP, 3); break; + + /* Replace STORE_FAST x LOAD_FAST x with DUP_TOP STORE_FAST x + Load and store must refer to the same slot. */ + case STORE_FAST: + j = GETARG(codestr, i); + if (codestr[i+3] != LOAD_FAST || + !ISBASICBLOCK(blocks, i, 5) || + j != GETARG(codestr, i+3)) + continue; + codestr[i] = DUP_TOP; + memset(codestr+i+1, NOP, 2); + codestr[i+3] = STORE_FAST; + SETARG(codestr, i+3, j); + break; } }