Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5e96e4f

Browse files
authored
gh-131798: JIT: Propagate the result in_BINARY_OP_SUBSCR_TUPLE_INT (GH-133003)
1 parent56c88e4 commit5e96e4f

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

‎Lib/test/test_capi/test_opt.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,6 +1923,23 @@ def testfunc(n):
19231923
self.assertNotIn("_GUARD_TOS_INT",uops)
19241924
self.assertIn("_CALL_LEN",uops)
19251925

1926+
deftest_binary_op_subscr_tuple_int(self):
1927+
deftestfunc(n):
1928+
x=0
1929+
for_inrange(n):
1930+
y= (1,2)
1931+
ify[0]==1:# _COMPARE_OP_INT + _GUARD_IS_TRUE_POP are removed
1932+
x+=1
1933+
returnx
1934+
1935+
res,ex=self._run_with_optimizer(testfunc,TIER2_THRESHOLD)
1936+
self.assertEqual(res,TIER2_THRESHOLD)
1937+
self.assertIsNotNone(ex)
1938+
uops=get_opnames(ex)
1939+
self.assertIn("_BINARY_OP_SUBSCR_TUPLE_INT",uops)
1940+
self.assertNotIn("_COMPARE_OP_INT",uops)
1941+
self.assertNotIn("_GUARD_IS_TRUE_POP",uops)
1942+
19261943

19271944
defglobal_identity(x):
19281945
returnx
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Propagate the return type of ``_BINARY_OP_SUBSCR_TUPLE_INT`` in JIT. Patch
2+
by Tomas Roun

‎Python/optimizer_bytecodes.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,27 @@ dummy_func(void) {
370370
res=sym_new_type(ctx,&PyUnicode_Type);
371371
}
372372

373+
op(_BINARY_OP_SUBSCR_TUPLE_INT, (tuple_st,sub_st--res)) {
374+
assert(sym_matches_type(tuple_st,&PyTuple_Type));
375+
if (sym_is_const(ctx,sub_st)) {
376+
assert(PyLong_CheckExact(sym_get_const(ctx,sub_st)));
377+
longindex=PyLong_AsLong(sym_get_const(ctx,sub_st));
378+
assert(index >=0);
379+
inttuple_length=sym_tuple_length(tuple_st);
380+
if (tuple_length==-1) {
381+
// Unknown length
382+
res=sym_new_not_null(ctx);
383+
}
384+
else {
385+
assert(index<tuple_length);
386+
res=sym_tuple_getitem(ctx,tuple_st,index);
387+
}
388+
}
389+
else {
390+
res=sym_new_not_null(ctx);
391+
}
392+
}
393+
373394
op(_TO_BOOL, (value--res)) {
374395
intalready_bool=optimize_to_bool(this_instr,ctx,value,&res);
375396
if (!already_bool) {

‎Python/optimizer_cases.c.h

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp