Skip to content

Commit f69228a

Browse files
UNARY_INVERT
1 parent e7a1e7e commit f69228a

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ def test_unary_negative_pop_top_load_const_inline_borrow(self):
16181618
def testfunc(n):
16191619
x = 0
16201620
for i in range(n):
1621-
a = 1 # This will make -1, which is definitely immortal
1621+
a = 1
16221622
result = -a
16231623
if result < 0:
16241624
x += 1
@@ -1648,6 +1648,23 @@ def testfunc(n):
16481648
self.assertNotIn("_UNARY_NOT", uops)
16491649
self.assertNotIn("_POP_TOP_LOAD_CONST_INLINE_BORROW", uops)
16501650

1651+
def test_unary_invert_pop_top_load_const_inline_borrow(self):
1652+
def testfunc(n):
1653+
x = 0
1654+
for i in range(n):
1655+
a = 0
1656+
result = ~a
1657+
if result < 0:
1658+
x += 1
1659+
return x
1660+
1661+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
1662+
self.assertEqual(res, TIER2_THRESHOLD)
1663+
self.assertIsNotNone(ex)
1664+
uops = get_opnames(ex)
1665+
self.assertNotIn("_UNARY_INVERT", uops)
1666+
self.assertNotIn("_POP_TOP_LOAD_CONST_INLINE_BORROW", uops)
1667+
16511668
def test_replace_with_true_pop_top_load_const_inline_borrow(self):
16521669
def testfunc(n):
16531670
x = 0

Python/optimizer_bytecodes.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ dummy_func(void) {
414414
}
415415

416416
op(_UNARY_INVERT, (value -- res)) {
417+
REPLACE_OPCODE_IF_EVALUATES_PURE(value);
417418
if (sym_matches_type(value, &PyLong_Type)) {
418419
res = sym_new_type(ctx, &PyLong_Type);
419420
}

Python/optimizer_cases.c.h

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)