Mercurial > cpython-lru_cache-weakref
diff Python/peephole.c @ 40116:3985d7e2067d legacy-trunk
Update the peephole optimizer to remove more dead code (jumps after returns)
and inline jumps to returns.
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Sat, 14 Oct 2006 21:33:38 +0000 |
| parents | 5e143944770b |
| children | 4e3481961fbb |
line wrap: on
line diff
--- a/Python/peephole.c Sat Oct 14 06:36:45 2006 +0000 +++ b/Python/peephole.c Sat Oct 14 21:33:38 2006 +0000 @@ -523,6 +523,13 @@ case SETUP_EXCEPT: case SETUP_FINALLY: tgt = GETJUMPTGT(codestr, i); + /* Replace JUMP_* to a RETURN into just a RETURN */ + if (UNCONDITIONAL_JUMP(opcode) && + codestr[tgt] == RETURN_VALUE) { + codestr[i] = RETURN_VALUE; + memset(codestr+i+1, NOP, 2); + continue; + } if (!UNCONDITIONAL_JUMP(codestr[tgt])) continue; tgttgt = GETJUMPTGT(codestr, tgt); @@ -540,12 +547,16 @@ goto exitUnchanged; /* Replace RETURN LOAD_CONST None RETURN with just RETURN */ + /* Remove unreachable JUMPs after RETURN */ case RETURN_VALUE: - if (i+4 >= codelen || - codestr[i+4] != RETURN_VALUE || - !ISBASICBLOCK(blocks,i,5)) + if (i+4 >= codelen) continue; - memset(codestr+i+1, NOP, 4); + if (codestr[i+4] == RETURN_VALUE && + ISBASICBLOCK(blocks,i,5)) + memset(codestr+i+1, NOP, 4); + else if (UNCONDITIONAL_JUMP(codestr[i+1]) && + ISBASICBLOCK(blocks,i,4)) + memset(codestr+i+1, NOP, 3); break; } }
