Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Include/internal/pycore_uop_ids.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Include/internal/pycore_uop_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,23 @@ def testfunc(n):
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
self.assertLessEqual(count_ops(ex, "_POP_TOP_INT"), 1)

def test_binary_op_subscr_dict(self):
def testfunc(n):
x = 0
d = {'a': 1, 'b': 2}
for _ in range(n):
v = d['a'] # _BINARY_OP_SUBSCR_DICT
if v == 1:
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.assertIn("_BINARY_OP_SUBSCR_DICT", uops)
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)

def test_call_type_1_guards_removed(self):
def testfunc(n):
x = 0
Expand Down
12 changes: 8 additions & 4 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1056,9 +1056,9 @@ dummy_func(
}

macro(BINARY_OP_SUBSCR_DICT) =
_GUARD_NOS_DICT + unused/5 + _BINARY_OP_SUBSCR_DICT;
_GUARD_NOS_DICT + unused/5 + _BINARY_OP_SUBSCR_DICT + POP_TOP + POP_TOP;

op(_BINARY_OP_SUBSCR_DICT, (dict_st, sub_st -- res)) {
op(_BINARY_OP_SUBSCR_DICT, (dict_st, sub_st -- res, ds, ss)) {
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
PyObject *dict = PyStackRef_AsPyObjectBorrow(dict_st);

Expand All @@ -1069,9 +1069,13 @@ dummy_func(
if (rc == 0) {
_PyErr_SetKeyError(sub);
}
DECREF_INPUTS();
ERROR_IF(rc <= 0); // not found or error
if (rc <= 0) {
ERROR_NO_POP();
}
res = PyStackRef_FromPyObjectSteal(res_o);
ds = dict_st;
ss = sub_st;
INPUTS_DEAD();
}

op(_BINARY_OP_SUBSCR_CHECK_FUNC, (container, unused -- container, unused, getitem)) {
Expand Down
26 changes: 10 additions & 16 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 23 additions & 15 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,12 @@ dummy_func(void) {
ss = sub_st;
}

op(_BINARY_OP_SUBSCR_DICT, (dict_st, sub_st -- res, ds, ss)) {
res = sym_new_not_null(ctx);
ds = dict_st;
ss = sub_st;
}

op(_TO_BOOL, (value -- res)) {
int already_bool = optimize_to_bool(this_instr, ctx, value, &res, false);
if (!already_bool) {
Expand Down
14 changes: 12 additions & 2 deletions Python/optimizer_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading