Skip to content

Commit 3a15ddd

Browse files
committed
gh-155486: merge test cases for TO_BOOL_INT
1 parent 88c8871 commit 3a15ddd

1 file changed

Lines changed: 4 additions & 16 deletions

File tree

Lib/test/test_capi/test_opt.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4882,32 +4882,20 @@ def f(n, value=1 << 100):
48824882
for _ in range(n):
48834883
if not value:
48844884
return 0
4885+
# The second check should reuse the exact-int type established by the first guard.
4886+
if not value:
4887+
return 0
48854888
return 1
48864889

48874890
res, ex = self._run_with_optimizer(f, TIER2_THRESHOLD)
48884891
self.assertEqual(res, 1)
48894892
self.assertIsNotNone(ex)
48904893
uops = get_opnames(ex)
48914894
self.assertIn("_TO_BOOL_INT", uops)
4895+
self.assertLessEqual(count_ops(ex, "_GUARD_TOS_EXACT_INT"), 1)
48924896
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 3)
48934897
self.assertIn("_POP_TOP_NOP", uops)
48944898

4895-
def test_to_bool_int_guard_elimination(self):
4896-
def testfunc(loops):
4897-
num = 0
4898-
for _ in range(loops):
4899-
_ = not num
4900-
a = not num
4901-
return a
4902-
4903-
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
4904-
self.assertTrue(res)
4905-
self.assertIsNotNone(ex)
4906-
to_bool_int_count = [opname for opname in iter_opnames(ex) if opname == "_TO_BOOL_INT"]
4907-
guard_tos_exact_int_count = [opname for opname in iter_opnames(ex) if opname == "_GUARD_TOS_EXACT_INT"]
4908-
self.assertGreaterEqual(len(to_bool_int_count), 2)
4909-
self.assertLessEqual(len(guard_tos_exact_int_count), 1)
4910-
49114899
def test_to_bool_list(self):
49124900
def f(n):
49134901
for i in range(n):

0 commit comments

Comments
 (0)