From b81201fb3f447c9cf1fd8fb7dd16c7d3adc6c20d Mon Sep 17 00:00:00 2001 From: Sacul0457Deve <183588943+Sacul0457@users.noreply.github.com.> Date: Sun, 22 Mar 2026 22:37:56 +0800 Subject: [PATCH 1/2] Restore Optimization and revert tests --- Lib/test/test_capi/test_opt.py | 7 ++----- Python/optimizer_bytecodes.c | 10 +++++----- Python/optimizer_cases.c.h | 10 +++++----- Python/optimizer_symbols.c | 2 +- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Lib/test/test_capi/test_opt.py b/Lib/test/test_capi/test_opt.py index bd9bc8a1a533c3..df127b55be4068 100644 --- a/Lib/test/test_capi/test_opt.py +++ b/Lib/test/test_capi/test_opt.py @@ -630,8 +630,6 @@ def dummy(x): self.assertIn("_PUSH_FRAME", uops) self.assertIn("_BINARY_OP_ADD_INT", uops) self.assertNotIn("_CHECK_PEP_523", uops) - self.assertNotIn("_GUARD_CODE_VERSION__PUSH_FRAME", uops) - self.assertNotIn("_GUARD_IP__PUSH_FRAME", uops) def test_int_type_propagate_through_range(self): def testfunc(n): @@ -1542,9 +1540,8 @@ def testfunc(n): self.assertIsNotNone(ex) uops = get_opnames(ex) self.assertIn("_PUSH_FRAME", uops) - # Both should be not present, as this is a call - # to a simple function with a known function version. - self.assertNotIn("_CHECK_FUNCTION_VERSION_INLINE", uops) + # Strength reduced version + self.assertIn("_CHECK_FUNCTION_VERSION_INLINE", uops) self.assertNotIn("_CHECK_FUNCTION_VERSION", uops) # Removed guard self.assertNotIn("_CHECK_FUNCTION_EXACT_ARGS", uops) diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c index f2d0e2940d7188..31bf6b39381dc2 100644 --- a/Python/optimizer_bytecodes.c +++ b/Python/optimizer_bytecodes.c @@ -864,12 +864,12 @@ dummy_func(void) { } op(_CHECK_FUNCTION_VERSION, (func_version/2, callable, self_or_null, unused[oparg] -- callable, self_or_null, unused[oparg])) { - if (sym_get_func_version(callable) == func_version) { - REPLACE_OP(this_instr, _NOP, 0, 0); - } - else { - sym_set_func_version(ctx, callable, func_version); + if (sym_is_const(ctx, callable) && sym_matches_type(callable, &PyFunction_Type)) { + assert(PyFunction_Check(sym_get_const(ctx, callable))); + ADD_OP(_CHECK_FUNCTION_VERSION_INLINE, 0, func_version); + uop_buffer_last(&ctx->out_buffer)->operand1 = (uintptr_t)sym_get_const(ctx, callable); } + sym_set_type(callable, &PyFunction_Type); } op(_CHECK_METHOD_VERSION, (func_version/2, callable, null, unused[oparg] -- callable, null, unused[oparg])) { diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h index 860bb02b7a0122..9a156f698d905f 100644 --- a/Python/optimizer_cases.c.h +++ b/Python/optimizer_cases.c.h @@ -3039,12 +3039,12 @@ JitOptRef callable; callable = stack_pointer[-2 - oparg]; uint32_t func_version = (uint32_t)this_instr->operand0; - if (sym_get_func_version(callable) == func_version) { - REPLACE_OP(this_instr, _NOP, 0, 0); - } - else { - sym_set_func_version(ctx, callable, func_version); + if (sym_is_const(ctx, callable) && sym_matches_type(callable, &PyFunction_Type)) { + assert(PyFunction_Check(sym_get_const(ctx, callable))); + ADD_OP(_CHECK_FUNCTION_VERSION_INLINE, 0, func_version); + uop_buffer_last(&ctx->out_buffer)->operand1 = (uintptr_t)sym_get_const(ctx, callable); } + sym_set_type(callable, &PyFunction_Type); break; } diff --git a/Python/optimizer_symbols.c b/Python/optimizer_symbols.c index c8697b32ab2dd4..e14ca1228d2f56 100644 --- a/Python/optimizer_symbols.c +++ b/Python/optimizer_symbols.c @@ -522,7 +522,7 @@ _Py_uop_sym_set_func_version(JitOptContext *ctx, JitOptRef ref, uint32_t version case JIT_SYM_PREDICATE_TAG: case JIT_SYM_TRUTHINESS_TAG: sym_set_bottom(ctx, sym); - return true; + return false; case JIT_SYM_RECORDED_VALUE_TAG: { PyObject *val = sym->recorded_value.value; if (Py_TYPE(val) != &PyFunction_Type || From 8a08593a93e7ad9e115688642d705fa55252a7b7 Mon Sep 17 00:00:00 2001 From: Sacul0457Deve <183588943+Sacul0457@users.noreply.github.com.> Date: Sun, 22 Mar 2026 23:16:20 +0800 Subject: [PATCH 2/2] revert and reduce change --- Lib/test/test_capi/test_opt.py | 7 +++++-- Python/optimizer_bytecodes.c | 10 +++++----- Python/optimizer_cases.c.h | 10 +++++----- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Lib/test/test_capi/test_opt.py b/Lib/test/test_capi/test_opt.py index df127b55be4068..bd9bc8a1a533c3 100644 --- a/Lib/test/test_capi/test_opt.py +++ b/Lib/test/test_capi/test_opt.py @@ -630,6 +630,8 @@ def dummy(x): self.assertIn("_PUSH_FRAME", uops) self.assertIn("_BINARY_OP_ADD_INT", uops) self.assertNotIn("_CHECK_PEP_523", uops) + self.assertNotIn("_GUARD_CODE_VERSION__PUSH_FRAME", uops) + self.assertNotIn("_GUARD_IP__PUSH_FRAME", uops) def test_int_type_propagate_through_range(self): def testfunc(n): @@ -1540,8 +1542,9 @@ def testfunc(n): self.assertIsNotNone(ex) uops = get_opnames(ex) self.assertIn("_PUSH_FRAME", uops) - # Strength reduced version - self.assertIn("_CHECK_FUNCTION_VERSION_INLINE", uops) + # Both should be not present, as this is a call + # to a simple function with a known function version. + self.assertNotIn("_CHECK_FUNCTION_VERSION_INLINE", uops) self.assertNotIn("_CHECK_FUNCTION_VERSION", uops) # Removed guard self.assertNotIn("_CHECK_FUNCTION_EXACT_ARGS", uops) diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c index 31bf6b39381dc2..f2d0e2940d7188 100644 --- a/Python/optimizer_bytecodes.c +++ b/Python/optimizer_bytecodes.c @@ -864,12 +864,12 @@ dummy_func(void) { } op(_CHECK_FUNCTION_VERSION, (func_version/2, callable, self_or_null, unused[oparg] -- callable, self_or_null, unused[oparg])) { - if (sym_is_const(ctx, callable) && sym_matches_type(callable, &PyFunction_Type)) { - assert(PyFunction_Check(sym_get_const(ctx, callable))); - ADD_OP(_CHECK_FUNCTION_VERSION_INLINE, 0, func_version); - uop_buffer_last(&ctx->out_buffer)->operand1 = (uintptr_t)sym_get_const(ctx, callable); + if (sym_get_func_version(callable) == func_version) { + REPLACE_OP(this_instr, _NOP, 0, 0); + } + else { + sym_set_func_version(ctx, callable, func_version); } - sym_set_type(callable, &PyFunction_Type); } op(_CHECK_METHOD_VERSION, (func_version/2, callable, null, unused[oparg] -- callable, null, unused[oparg])) { diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h index 9a156f698d905f..860bb02b7a0122 100644 --- a/Python/optimizer_cases.c.h +++ b/Python/optimizer_cases.c.h @@ -3039,12 +3039,12 @@ JitOptRef callable; callable = stack_pointer[-2 - oparg]; uint32_t func_version = (uint32_t)this_instr->operand0; - if (sym_is_const(ctx, callable) && sym_matches_type(callable, &PyFunction_Type)) { - assert(PyFunction_Check(sym_get_const(ctx, callable))); - ADD_OP(_CHECK_FUNCTION_VERSION_INLINE, 0, func_version); - uop_buffer_last(&ctx->out_buffer)->operand1 = (uintptr_t)sym_get_const(ctx, callable); + if (sym_get_func_version(callable) == func_version) { + REPLACE_OP(this_instr, _NOP, 0, 0); + } + else { + sym_set_func_version(ctx, callable, func_version); } - sym_set_type(callable, &PyFunction_Type); break; }