mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
GH-131798: Turn _LOAD_SMALL_INT into _LOAD_CONST_INLINE_BORROW in the JIT (GH-134406)
This commit is contained in:
parent
3effede97c
commit
8c5e5557c6
4 changed files with 21 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
JIT: replace ``_LOAD_SMALL_INT`` with ``_LOAD_CONST_INLINE_BORROW``
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
5
Python/optimizer_cases.c.h
generated
5
Python/optimizer_cases.c.h
generated
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue