Skip to content

Commit

Permalink
prepare for common subexpr elimination
Browse files Browse the repository at this point in the history
  • Loading branch information
Fidget-Spinner committed Dec 12, 2023
1 parent 7ac7a79 commit 43d8e51
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 32 deletions.
20 changes: 18 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.

26 changes: 23 additions & 3 deletions Lib/test/test_capi/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2402,7 +2402,7 @@ def testfunc(loops):
while num < loops:
x = num + num
y = 1
a = (num + num) + y
a = x + y
num += 1
return a

Expand Down Expand Up @@ -2438,7 +2438,7 @@ def testfunc(loops):
# binop_count = [opname for opname, _, _ in ex if opname == "_BINARY_OP_ADD_INT"]
# self.assertEqual(len(binop_count), 3)
#
# def test_int_impure_region(self):
# def test_int_impure_region_attr(self):
# class A:
# foo = 1
# def testfunc(loops):
Expand All @@ -2460,7 +2460,27 @@ def testfunc(loops):
# self.assertIsNotNone(ex)
# binop_count = [opname for opname, _, _ in ex if opname == "_BINARY_OP_ADD_INT"]
# self.assertEqual(len(binop_count), 3)

# def test_int_large_pure_region_attr(self):
# class A:
# foo = 1
# def testfunc(loops):
# num = 0
# while num < loops:
# x = num + num + num - num + num - num + num + num + num - num + num - num
# y = 1
# a = x + num + num + num
# num += 1
# return a
#
# opt = _testinternalcapi.get_uop_optimizer()
# res = None
# with temporary_optimizer(opt):
# res = testfunc(64)
#
# ex = get_first_executor(testfunc)
# self.assertIsNotNone(ex)
# binop_count = [opname for opname, _, _ in ex if opname == "_BINARY_OP_ADD_INT"]
# self.assertEqual(len(binop_count), 3)



Expand Down
11 changes: 11 additions & 0 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2705,6 +2705,7 @@ dummy_func(
DEOPT_IF(r->len <= 0);
}

// TODO this is not pure but we should still be able to type propagate
op(_ITER_NEXT_RANGE, (iter -- iter, next: ~(PYINT_TYPE))) {
_PyRangeIterObject *r = (_PyRangeIterObject *)iter;
assert(Py_TYPE(r) == &PyRangeIter_Type);
Expand Down Expand Up @@ -4057,6 +4058,16 @@ dummy_func(
*target = tos;
}

pure op(_STORE_COMMON, (addr/4, value --)) {
TIER_TWO_ONLY
*((PyObject **)addr) = value;
}

pure op(_LOAD_COMMON, (addr/4 -- value)) {
TIER_TWO_ONLY
value = *((PyObject **)addr);
}

op(_INSERT, (unused[oparg], top -- top, unused[oparg])) {
TIER_TWO_ONLY
// Inserts TOS at position specified by oparg;
Expand Down
20 changes: 20 additions & 0 deletions Python/executor_cases.c.h

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

Loading

0 comments on commit 43d8e51

Please sign in to comment.