summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_capi
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2024-04-22 12:34:06 (GMT)
committerGitHub <noreply@github.com>2024-04-22 12:34:06 (GMT)
commita6647d16abf4dd65997865e857371673238e60bf (patch)
treeb4ebfbfb86f0962d766f09d3d54513a9b38b0669 /Lib/test/test_capi
parentceb6038b053c403bed3ca3a8bd17b7e3fc9aab7d (diff)
downloadcpython-a6647d16abf4dd65997865e857371673238e60bf.zip
cpython-a6647d16abf4dd65997865e857371673238e60bf.tar.gz
cpython-a6647d16abf4dd65997865e857371673238e60bf.tar.bz2
GH-115480: Reduce guard strength for binary ops when type of one operand is known already (GH-118050)
Diffstat (limited to 'Lib/test/test_capi')
-rw-r--r--Lib/test/test_capi/test_opt.py44
1 files changed, 42 insertions, 2 deletions
diff --git a/Lib/test/test_capi/test_opt.py b/Lib/test/test_capi/test_opt.py
index 28d1873..ae23ead 100644
--- a/Lib/test/test_capi/test_opt.py
+++ b/Lib/test/test_capi/test_opt.py
@@ -903,10 +903,50 @@ class TestUopsOptimization(unittest.TestCase):
self.assertTrue(res)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
- guard_both_float_count = [opname for opname in iter_opnames(ex) if opname == "_GUARD_BOTH_INT"]
- self.assertLessEqual(len(guard_both_float_count), 1)
+ guard_both_int_count = [opname for opname in iter_opnames(ex) if opname == "_GUARD_BOTH_INT"]
+ self.assertLessEqual(len(guard_both_int_count), 1)
self.assertIn("_COMPARE_OP_INT", uops)
+ def test_compare_op_type_propagation_int_partial(self):
+ def testfunc(n):
+ a = 1
+ for _ in range(n):
+ if a > 2:
+ x = 0
+ if a < 2:
+ x = 1
+ return x
+
+ res, ex = self._run_with_optimizer(testfunc, 32)
+ self.assertEqual(res, 1)
+ self.assertIsNotNone(ex)
+ uops = get_opnames(ex)
+ guard_left_int_count = [opname for opname in iter_opnames(ex) if opname == "_GUARD_NOS_INT"]
+ guard_both_int_count = [opname for opname in iter_opnames(ex) if opname == "_GUARD_BOTH_INT"]
+ self.assertLessEqual(len(guard_left_int_count), 1)
+ self.assertEqual(len(guard_both_int_count), 0)
+ self.assertIn("_COMPARE_OP_INT", uops)
+
+ def test_compare_op_type_propagation_float_partial(self):
+ def testfunc(n):
+ a = 1.0
+ for _ in range(n):
+ if a > 2.0:
+ x = 0
+ if a < 2.0:
+ x = 1
+ return x
+
+ res, ex = self._run_with_optimizer(testfunc, 32)
+ self.assertEqual(res, 1)
+ self.assertIsNotNone(ex)
+ uops = get_opnames(ex)
+ guard_left_float_count = [opname for opname in iter_opnames(ex) if opname == "_GUARD_NOS_FLOAT"]
+ guard_both_float_count = [opname for opname in iter_opnames(ex) if opname == "_GUARD_BOTH_FLOAT"]
+ self.assertLessEqual(len(guard_left_float_count), 1)
+ self.assertEqual(len(guard_both_float_count), 0)
+ self.assertIn("_COMPARE_OP_FLOAT", uops)
+
def test_compare_op_type_propagation_unicode(self):
def testfunc(n):
a = ""