Skip to content

Commit 0d2e040

Browse files
committed
Improve handling of _POP_TOP_LOAD_CONST_INLINE_BORROW and _REPLACE_WITH_TRUE
1 parent 0dfd1fe commit 0d2e040

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

Python/optimizer_analysis.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ remove_unneeded_uops(_PyUOpInstruction *buffer, int buffer_size)
543543
last_set_ip = pc;
544544
break;
545545
case _POP_TOP:
546+
case _POP_TOP_LOAD_CONST_INLINE_BORROW:
546547
{
547548
_PyUOpInstruction *last = &buffer[pc-1];
548549
while (last->opcode == _NOP) {
@@ -554,9 +555,14 @@ remove_unneeded_uops(_PyUOpInstruction *buffer, int buffer_size)
554555
last->opcode == _COPY
555556
) {
556557
last->opcode = _NOP;
557-
buffer[pc].opcode = _NOP;
558+
if (buffer[pc].opcode == _POP_TOP_LOAD_CONST_INLINE_BORROW) {
559+
buffer[pc].opcode = _LOAD_CONST_INLINE_BORROW;
560+
}
561+
else {
562+
buffer[pc].opcode = _NOP;
563+
}
558564
}
559-
if (last->opcode == _REPLACE_WITH_TRUE) {
565+
if (last->opcode == _POP_TOP_LOAD_CONST_INLINE_BORROW) {
560566
last->opcode = _NOP;
561567
}
562568
break;

Python/optimizer_bytecodes.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,12 @@ dummy_func(void) {
922922
self_or_null = sym_new_unknown(ctx);
923923
}
924924

925+
op(_REPLACE_WITH_TRUE, (value -- res)) {
926+
(void)value;
927+
REPLACE_OP(this_instr, _POP_TOP_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)Py_True);
928+
res = sym_new_const(ctx, Py_True);
929+
}
930+
925931
op(_JUMP_TO_TOP, (--)) {
926932
ctx->done = true;
927933
}

Python/optimizer_cases.c.h

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)