Skip to content

Commit ee6e90b

Browse files
committed
gh-131798: JIT: replace _LOAD_SMALL_INT with
`_LOAD_CONST_INLINE_BORROW` Signed-off-by: Manjusaka <me@manjusaka.me> add news Signed-off-by: Manjusaka <me@manjusaka.me> add tests Signed-off-by: Manjusaka <me@manjusaka.me> fix review idea Signed-off-by: Manjusaka <me@manjusaka.me>
1 parent c740fe3 commit ee6e90b

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,6 +2156,17 @@ def testfunc(n):
21562156
self.assertIn("_GUARD_TYPE_VERSION", uops)
21572157
self.assertNotIn("_CHECK_ATTR_CLASS", uops)
21582158

2159+
def test_load_small_int(self):
2160+
def testfunc(n):
2161+
x = 0
2162+
for i in range(n):
2163+
x += 1
2164+
return x
2165+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
2166+
self.assertEqual(res, TIER2_THRESHOLD)
2167+
self.assertIsNotNone(ex)
2168+
uops = get_opnames(ex)
2169+
self.assertIn("_LOAD_CONST_INLINE_BORROW", uops)
21592170

21602171
def global_identity(x):
21612172
return x
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
JIT: replace ``_LOAD_SMALL_INT`` with ``_LOAD_CONST_INLINE_BORROW``

Python/optimizer_bytecodes.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ dummy_func(void) {
529529

530530
op(_LOAD_SMALL_INT, (-- value)) {
531531
PyObject *val = PyLong_FromLong(this_instr->oparg);
532+
REPLACE_OP(this_instr, _LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)val);
532533
value = sym_new_const(ctx, val);
533534
}
534535

Python/optimizer_cases.c.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)