From 46151648ca8ba1edd2a2783e8e154692a13d8ea8 Mon Sep 17 00:00:00 2001 From: "Tomas R." Date: Sat, 7 Jun 2025 01:44:43 +0200 Subject: GH-131798: Optimize away type(x) in the JIT when the result is known (GH-135194) --- Python/optimizer_bytecodes.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Python/optimizer_bytecodes.c') diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c index b4220e2c627..12efaacd8f0 100644 --- a/Python/optimizer_bytecodes.c +++ b/Python/optimizer_bytecodes.c @@ -937,8 +937,11 @@ dummy_func(void) { } op(_CALL_TYPE_1, (unused, unused, arg -- res)) { - if (sym_has_type(arg)) { - res = sym_new_const(ctx, (PyObject *)sym_get_type(arg)); + PyObject* type = (PyObject *)sym_get_type(arg); + if (type) { + res = sym_new_const(ctx, type); + REPLACE_OP(this_instr, _POP_CALL_ONE_LOAD_CONST_INLINE_BORROW, 0, + (uintptr_t)type); } else { res = sym_new_not_null(ctx); -- cgit v1.2.3