Skip to content

Commit 3b37082

Browse files
UNARY_NOT
1 parent e75ca80 commit 3b37082

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,23 @@ def f(n):
16141614
# But all of the appends we care about are still there:
16151615
self.assertEqual(uops.count("_CALL_LIST_APPEND"), len("ABCDEFG"))
16161616

1617+
def test_unary_not_pop_top_load_const_inline_borrow(self):
1618+
def testfunc(n):
1619+
x = 0
1620+
for i in range(n):
1621+
a = 42
1622+
result = not a
1623+
if result:
1624+
x += 1
1625+
return x
1626+
1627+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
1628+
self.assertEqual(res, 0)
1629+
self.assertIsNotNone(ex)
1630+
uops = get_opnames(ex)
1631+
self.assertNotIn("_UNARY_NOT", uops)
1632+
self.assertNotIn("_POP_TOP_LOAD_CONST_INLINE_BORROW", uops)
1633+
16171634
def test_replace_with_true_pop_top_load_const_inline_borrow(self):
16181635
def testfunc(n):
16191636
x = 0

Python/optimizer_bytecodes.c

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

400400
op(_UNARY_NEGATIVE, (value -- res)) {
401+
REPLACE_OPCODE_IF_EVALUATES_PURE(value);
401402
if (sym_is_compact_int(value)) {
402403
res = sym_new_compact_int(ctx);
403404
}

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)