diff options
author | Brandt Bucher <brandtbucher@microsoft.com> | 2025-04-21 16:58:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-21 16:58:55 (GMT) |
commit | 4f7f72ce34f7825e50346ed0c878fc36ef9421ca (patch) | |
tree | c507a9012c7a04d434a4a3607ba094f8979cf7ae /Python/optimizer_analysis.c | |
parent | 9be364568835e467199ccd65bbcd786f9c8171dc (diff) | |
download | cpython-4f7f72ce34f7825e50346ed0c878fc36ef9421ca.zip cpython-4f7f72ce34f7825e50346ed0c878fc36ef9421ca.tar.gz cpython-4f7f72ce34f7825e50346ed0c878fc36ef9421ca.tar.bz2 |
GH-130415: Improve the JIT's unneeded uop removal pass (GH-132333)
Diffstat (limited to 'Python/optimizer_analysis.c')
-rw-r--r-- | Python/optimizer_analysis.c | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c index ab28fae..387ebc8 100644 --- a/Python/optimizer_analysis.c +++ b/Python/optimizer_analysis.c @@ -555,28 +555,47 @@ remove_unneeded_uops(_PyUOpInstruction *buffer, int buffer_size) } break; case _POP_TOP: + case _POP_TOP_LOAD_CONST_INLINE: + case _POP_TOP_LOAD_CONST_INLINE_BORROW: + case _POP_TWO_LOAD_CONST_INLINE_BORROW: + optimize_pop_top_again: { _PyUOpInstruction *last = &buffer[pc-1]; while (last->opcode == _NOP) { last--; } - if (last->opcode == _LOAD_CONST_INLINE || - last->opcode == _LOAD_CONST_INLINE_BORROW || - last->opcode == _LOAD_FAST || - last->opcode == _LOAD_FAST_BORROW || - last->opcode == _COPY - ) { - last->opcode = _NOP; - buffer[pc].opcode = _NOP; - } - if (last->opcode == _REPLACE_WITH_TRUE) { - last->opcode = _NOP; + switch (last->opcode) { + case _POP_TWO_LOAD_CONST_INLINE_BORROW: + last->opcode = _POP_TOP; + break; + case _POP_TOP_LOAD_CONST_INLINE: + case _POP_TOP_LOAD_CONST_INLINE_BORROW: + last->opcode = _NOP; + goto optimize_pop_top_again; + case _COPY: + case _LOAD_CONST_INLINE: + case _LOAD_CONST_INLINE_BORROW: + case _LOAD_FAST: + case _LOAD_FAST_BORROW: + case _LOAD_SMALL_INT: + last->opcode = _NOP; + if (opcode == _POP_TOP) { + opcode = buffer[pc].opcode = _NOP; + } + else if (opcode == _POP_TOP_LOAD_CONST_INLINE) { + opcode = buffer[pc].opcode = _LOAD_CONST_INLINE; + } + else if (opcode == _POP_TOP_LOAD_CONST_INLINE_BORROW) { + opcode = buffer[pc].opcode = _LOAD_CONST_INLINE_BORROW; + } + else { + assert(opcode == _POP_TWO_LOAD_CONST_INLINE_BORROW); + opcode = buffer[pc].opcode = _POP_TOP_LOAD_CONST_INLINE_BORROW; + goto optimize_pop_top_again; + } } - break; + _Py_FALLTHROUGH; } - case _JUMP_TO_TOP: - case _EXIT_TRACE: - return pc + 1; default: { /* _PUSH_FRAME doesn't escape or error, but it @@ -591,7 +610,11 @@ remove_unneeded_uops(_PyUOpInstruction *buffer, int buffer_size) buffer[last_set_ip].opcode = _SET_IP; last_set_ip = -1; } + break; } + case _JUMP_TO_TOP: + case _EXIT_TRACE: + return pc + 1; } } Py_UNREACHABLE(); |