GH-131798: Split up and optimize CALL_ISINSTANCE (GH-133339)

This commit is contained in:
Tomas R. 2025-05-08 23:26:30 +02:00 committed by GitHub
parent b2fabce6ab
commit c492ac7252
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 392 additions and 301 deletions

View file

@ -1942,6 +1942,23 @@ class TestUopsOptimization(unittest.TestCase):
self.assertNotIn("_COMPARE_OP_INT", uops)
self.assertNotIn("_GUARD_IS_TRUE_POP", uops)
def test_call_isinstance_guards_removed(self):
def testfunc(n):
x = 0
for _ in range(n):
y = isinstance(42, int)
if y:
x += 1
return x
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
self.assertEqual(res, TIER2_THRESHOLD)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertIn("_CALL_ISINSTANCE", uops)
self.assertNotIn("_GUARD_THIRD_NULL", uops)
self.assertNotIn("_GUARD_CALLABLE_ISINSTANCE", uops)
def global_identity(x):
return x