8000 GH-130415: Optimize constant comparison in JIT builds by savannahostrowski · Pull Request #131489 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-130415: Optimize constant comparison in JIT builds #131489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 21, 2025
Prev Previous commit
Next Next commit
add test for optimization
  • Loading branch information
savannahostrowski committed Mar 20, 2025
commit 697323b4bedfd4bb65f626846144d257b7420c59
18 changes: 18 additions & 0 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,7 @@ def testfunc(n):
self.assertNotIn("_GUARD_NOS_INT", uops)
self.assertNotIn("_GUARD_TOS_INT", uops)


def test_decref_escapes(self):
class Convert9999ToNone:
def __del__(self):
Expand Down Expand Up @@ -1564,6 +1565,23 @@ def f(n):
# But all of the appends we care about are still there:
self.assertEqual(uops.count("_CALL_LIST_APPEND"), len("ABCDEFG"))

def test_compare_pop_two_load_const_inline_borrow(self):
def testfunc(n):
x = 0
for _ in range(n):
a = 10
b = 10
if a == b:
x += 1
return x

res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
self.assertEqual(res, 1)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertNotIn("_COMPARE_OP_INT", uops)
self.assertNotIn("_POP_TWO_LOAD_CONST_INLINE_BORROW", uops)

def global_identity(x):
return x

Expand Down
0