Skip to content

GH-132732: Use pure op machinery to optimize various instructions with _POP_TOP and _POP_TWO #137577

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
UNARY_NEGATIVE
  • Loading branch information
savannahostrowski committed Aug 6, 2025
commit e7a1e7ea473219b2add60e7b6f7551797c23e51a
17 changes: 17 additions & 0 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,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_unary_negative_pop_top_load_const_inline_borrow(self):
def testfunc(n):
x = 0
for i in range(n):
a = 1 # This will make -1, which is definitely immortal
result = -a
if result < 0:
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.assertNotIn("_UNARY_NEGATIVE", uops)
self.assertNotIn("_POP_TOP_LOAD_CONST_INLINE_BORROW", uops)

def test_unary_not_pop_top_load_const_inline_borrow(self):
def testfunc(n):
x = 0
Expand Down