Skip to content

Commit 88c8871

Browse files
committed
gh-155486: Add test for TO_BOOL_INT guard elimination
1 parent 5e5024a commit 88c8871

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

Lib/test/test_capi/test_opt.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4892,6 +4892,22 @@ def f(n, value=1 << 100):
48924892
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 3)
48934893
self.assertIn("_POP_TOP_NOP", uops)
48944894

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+
48954911
def test_to_bool_list(self):
48964912
def f(n):
48974913
for i in range(n):

0 commit comments

Comments
 (0)