Skip to content

Commit db7f2e7

Browse files
Optimize compare_op_str and add test
1 parent f5d2210 commit db7f2e7

File tree

3 files changed

+98
-21
lines changed

3 files changed

+98
-21
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,6 @@ def testfunc(n):
843843
self.assertLessEqual(len(guard_tos_unicode_count), 1)
844844
self.assertLessEqual(len(guard_nos_unicode_count), 1)
845845
self.assertIn("_COMPARE_OP_STR", uops)
846-
self.assertNotIn("_POP_TWO_LOAD_CONST_INLINE_BORROW", uops)
847846

848847
def test_type_inconsistency(self):
849848
ns = {}
@@ -1615,7 +1614,7 @@ def f(n):
16151614
# But all of the appends we care about are still there:
16161615
self.assertEqual(uops.count("_CALL_LIST_APPEND"), len("ABCDEFG"))
16171616

1618-
def test_compare_pop_two_load_const_inline_borrow(self):
1617+
def test_compare_op_int_pop_two_load_const_inline_borrow(self):
16191618
def testfunc(n):
16201619
x = 0
16211620
for _ in range(n):
@@ -1632,6 +1631,23 @@ def testfunc(n):
16321631
self.assertNotIn("_COMPARE_OP_INT", uops)
16331632
self.assertNotIn("_POP_TWO_LOAD_CONST_INLINE_BORROW", uops)
16341633

1634+
def test_compare_op_str_pop_two_load_const_inline_borrow(self):
1635+
def testfunc(n):
1636+
x = 0
1637+
for _ in range(n):
1638+
a = "foo"
1639+
b = "foo"
1640+
if a == b:
1641+
x += 1
1642+
return x
1643+
1644+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
1645+
self.assertEqual(res, TIER2_THRESHOLD)
1646+
self.assertIsNotNone(ex)
1647+
uops = get_opnames(ex)
1648+
self.assertNotIn("_COMPARE_OP_STR", uops)
1649+
self.assertNotIn("_POP_TWO_LOAD_CONST_INLINE_BORROW", uops)
1650+
16351651
def test_to_bool_bool_contains_op_set(self):
16361652
"""
16371653
Test that _TO_BOOL_BOOL is removed from code like:

Python/optimizer_bytecodes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ dummy_func(void) {
440440
}
441441

442442
op(_COMPARE_OP_STR, (left, right -- res)) {
443-
// REPLACE_OPCODE_IF_EVALUATES_PURE(left, right);
443+
REPLACE_OPCODE_IF_EVALUATES_PURE(left, right);
444444
res = sym_new_type(ctx, &PyBool_Type);
445445
}
446446

Python/optimizer_cases.c.h

Lines changed: 79 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)