Skip to content

Commit 9477098

Browse files
Add a test
1 parent f22ea64 commit 9477098

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,6 +2540,25 @@ def f(n):
25402540
self.assertNotIn("_LOAD_ATTR_METHOD_NO_DICT", uops)
25412541
self.assertNotIn("_LOAD_ATTR_METHOD_LAZY_DICT", uops)
25422542

2543+
def test_store_fast_refcount_elimination(self):
2544+
def foo(x):
2545+
# Since x is known to be
2546+
# a constant value (1) here,
2547+
# The refcount is eliminated in the STOER_FAST.
2548+
x = 2
2549+
return x
2550+
def testfunc(n):
2551+
# The STORE_FAST for the range here needs a POP_TOP
2552+
# (for now, until we do loop peeling).
2553+
for _ in range(n):
2554+
foo(1)
2555+
2556+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
2557+
self.assertIsNotNone(ex)
2558+
uops = get_opnames(ex)
2559+
self.assertIn("_POP_TOP_NOP", uops)
2560+
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 1)
2561+
25432562
def test_float_op_refcount_elimination(self):
25442563
def testfunc(args):
25452564
a, b, n = args

0 commit comments

Comments
 (0)