From: Nadeshiko Manju Date: Thu, 22 May 2025 13:54:57 +0000 (+0800) Subject: GH-131798: Turn _LOAD_SMALL_INT into _LOAD_CONST_INLINE_BORROW in the JIT (GH-134406) X-Git-Tag: v3.15.0a1~1572 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8c5e5557c64a8d6310b2a958f576d5eb245cb1b6;p=thirdparty%2FPython%2Fcpython.git GH-131798: Turn _LOAD_SMALL_INT into _LOAD_CONST_INLINE_BORROW in the JIT (GH-134406) --- diff --git a/Lib/test/test_capi/test_opt.py b/Lib/test/test_capi/test_opt.py index 98b434313e4d..2b777acb1ec4 100644 --- a/Lib/test/test_capi/test_opt.py +++ b/Lib/test/test_capi/test_opt.py @@ -2156,6 +2156,18 @@ class TestUopsOptimization(unittest.TestCase): self.assertIn("_GUARD_TYPE_VERSION", uops) self.assertNotIn("_CHECK_ATTR_CLASS", uops) + def test_load_small_int(self): + def testfunc(n): + x = 0 + for i in range(n): + x += 1 + return x + res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD) + self.assertEqual(res, TIER2_THRESHOLD) + self.assertIsNotNone(ex) + uops = get_opnames(ex) + self.assertNotIn("_LOAD_SMALL_INT", uops) + self.assertIn("_LOAD_CONST_INLINE_BORROW", uops) def global_identity(x): return x diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-05-21-13-57-26.gh-issue-131798.QwS5Bb.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-05-21-13-57-26.gh-issue-131798.QwS5Bb.rst new file mode 100644 index 000000000000..f873bbfb4dcb --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-05-21-13-57-26.gh-issue-131798.QwS5Bb.rst @@ -0,0 +1 @@ +JIT: replace ``_LOAD_SMALL_INT`` with ``_LOAD_CONST_INLINE_BORROW`` diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c index f12cd7b968cf..b9ebd8678e0f 100644 --- a/Python/optimizer_bytecodes.c +++ b/Python/optimizer_bytecodes.c @@ -528,7 +528,10 @@ dummy_func(void) { } op(_LOAD_SMALL_INT, (-- value)) { - PyObject *val = PyLong_FromLong(this_instr->oparg); + PyObject *val = PyLong_FromLong(oparg); + assert(val); + assert(_Py_IsImmortal(val)); + REPLACE_OP(this_instr, _LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)val); value = sym_new_const(ctx, val); } diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h index 602f5e2cfaf7..0ba45e1f58fe 100644 --- a/Python/optimizer_cases.c.h +++ b/Python/optimizer_cases.c.h @@ -79,7 +79,10 @@ case _LOAD_SMALL_INT: { JitOptSymbol *value; - PyObject *val = PyLong_FromLong(this_instr->oparg); + PyObject *val = PyLong_FromLong(oparg); + assert(val); + assert(_Py_IsImmortal(val)); + REPLACE_OP(this_instr, _LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)val); value = sym_new_const(ctx, val); stack_pointer[0] = value; stack_pointer += 1;