Skip to content

Commit 4b99dac

Browse files
committed
do not replace const ops
1 parent 94a1907 commit 4b99dac

File tree

3 files changed

+10
-48
lines changed

3 files changed

+10
-48
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,21 +2234,6 @@ def testfunc(n):
22342234
self.assertNotIn("_GUARD_TOS_INT", uops)
22352235
self.assertNotIn("_GUARD_NOS_INT", uops)
22362236

2237-
def test_unary_invert_replace(self):
2238-
def testfunc(n):
2239-
for _ in range(n):
2240-
a = -1
2241-
a = ~a
2242-
2243-
testfunc(TIER2_THRESHOLD)
2244-
2245-
ex = get_first_executor(testfunc)
2246-
self.assertIsNotNone(ex)
2247-
uops = get_opnames(ex)
2248-
2249-
self.assertNotIn("_UNARY_INVERT", uops)
2250-
self.assertIn("_LOAD_CONST_INLINE_BORROW", uops)
2251-
22522237

22532238
def global_identity(x):
22542239
return x

Python/optimizer_bytecodes.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -468,22 +468,11 @@ dummy_func(void) {
468468
}
469469

470470
op(_UNARY_INVERT, (value -- res)) {
471-
if (sym_is_const(ctx, value)) {
472-
PyObject *temp = PyNumber_Invert(sym_get_const(ctx, value));
473-
if (temp == NULL) {
474-
goto error;
475-
}
476-
if (_Py_IsImmortal(temp)) {
477-
REPLACE_OP(this_instr, _POP_TOP_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)temp);
478-
}
479-
res = sym_new_const(ctx, temp);
480-
Py_DECREF(temp);
481-
} else {
482-
if (sym_matches_type(value, &PyLong_Type) || sym_matches_type(value, &PyBool_Type)) {
483-
res = sym_new_type(ctx, &PyLong_Type);
484-
} else {
485-
res = sym_new_not_null(ctx);
486-
}
471+
if (sym_matches_type(value, &PyLong_Type) || sym_matches_type(value, &PyBool_Type)) {
472+
res = sym_new_type(ctx, &PyLong_Type);
473+
}
474+
else {
475+
res = sym_new_not_null(ctx);
487476
}
488477
}
489478

Python/optimizer_cases.c.h

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

0 commit comments

Comments
 (0)