| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1923,6 +1923,23 @@ def testfunc(n): | |||
| 1923 | 1923 | self.assertNotIn("_GUARD_TOS_INT", uops) | |
| 1924 | 1924 | self.assertIn("_CALL_LEN", uops) | |
| 1925 | 1925 | ||
| 1926 | + def test_binary_op_subscr_tuple_int(self): | ||
| 1927 | + def testfunc(n): | ||
| 1928 | + x = 0 | ||
| 1929 | + for _ in range(n): | ||
| 1930 | + y = (1, 2) | ||
| 1931 | + if y[0] == 1: # _COMPARE_OP_INT + _GUARD_IS_TRUE_POP are removed | ||
| 1932 | + x += 1 | ||
| 1933 | + return x | ||
| 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 | + | ||
| 1926 | 1943 | ||
| 1927 | 1944 | def global_identity(x): | |
| 1928 | 1945 | return x | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Propagate the return type of ``_BINARY_OP_SUBSCR_TUPLE_INT`` in JIT. Patch | ||
| 2 | + by Tomas Roun | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -370,6 +370,27 @@ dummy_func(void) { | |||
| 370 | 370 | res = sym_new_type(ctx, &PyUnicode_Type); | |
| 371 | 371 | } | |
| 372 | 372 | ||
| 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 | + long index = PyLong_AsLong(sym_get_const(ctx, sub_st)); | ||
| 378 | + assert(index >= 0); | ||
| 379 | + int tuple_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 | + | ||
| 373 | 394 | op(_TO_BOOL, (value -- res)) { | |
| 374 | 395 | int already_bool = optimize_to_bool(this_instr, ctx, value, &res); | |
| 375 | 396 | if (!already_bool) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments