Skip to content

Commit 9bef4a4

Browse files
revert changes for add,multiply,sub int
1 parent fce79a6 commit 9bef4a4

File tree

7 files changed

+108
-95
lines changed

7 files changed

+108
-95
lines changed

Include/internal/pycore_opcode_metadata.h

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

Include/internal/pycore_uop_metadata.h

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

Python/executor_cases.c.h

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

Python/generated_cases.c.h

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

Python/optimizer_bytecodes.c

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,61 @@ dummy_func(void) {
222222
}
223223

224224
op(_BINARY_OP_ADD_INT, (left, right -- res)) {
225-
REPLACE_OPCODE_IF_EVALUATES_PURE(left, right);
226-
res = sym_new_type(ctx, &PyLong_Type);
225+
if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) {
226+
assert(PyLong_CheckExact(sym_get_const(ctx, left)));
227+
assert(PyLong_CheckExact(sym_get_const(ctx, right)));
228+
PyObject *temp = _PyLong_Add((PyLongObject *)sym_get_const(ctx, left),
229+
(PyLongObject *)sym_get_const(ctx, right));
230+
if (temp == NULL) {
231+
goto error;
232+
}
233+
res = sym_new_const(ctx, temp);
234+
Py_DECREF(temp);
235+
// TODO gh-115506:
236+
// replace opcode with constant propagated one and add tests!
237+
}
238+
else {
239+
res = sym_new_type(ctx, &PyLong_Type);
240+
}
227241
}
228242

229243
op(_BINARY_OP_SUBTRACT_INT, (left, right -- res)) {
230-
REPLACE_OPCODE_IF_EVALUATES_PURE(left, right);
244+
if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) {
245+
assert(PyLong_CheckExact(sym_get_const(ctx, left)));
246+
assert(PyLong_CheckExact(sym_get_const(ctx, right)));
247+
PyObject *temp = _PyLong_Subtract((PyLongObject *)sym_get_const(ctx, left),
248+
(PyLongObject *)sym_get_const(ctx, right));
249+
if (temp == NULL) {
250+
goto error;
251+
}
252+
res = sym_new_const(ctx, temp);
253+
Py_DECREF(temp);
254+
// TODO gh-115506:
255+
// replace opcode with constant propagated one and add tests!
256+
}
257+
else {
258+
res = sym_new_type(ctx, &PyLong_Type);
259+
}
231260
res = sym_new_type(ctx, &PyLong_Type);
232261
}
233262

234263
op(_BINARY_OP_MULTIPLY_INT, (left, right -- res)) {
235-
REPLACE_OPCODE_IF_EVALUATES_PURE(left, right);
264+
if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) {
265+
assert(PyLong_CheckExact(sym_get_const(ctx, left)));
266+
assert(PyLong_CheckExact(sym_get_const(ctx, right)));
267+
PyObject *temp = _PyLong_Multiply((PyLongObject *)sym_get_const(ctx, left),
268+
(PyLongObject *)sym_get_const(ctx, right));
269+
if (temp == NULL) {
270+
goto error;
271+
}
272+
res = sym_new_const(ctx, temp);
273+
Py_DECREF(temp);
274+
// TODO gh-115506:
275+
// replace opcode with constant propagated one and add tests!
276+
}
277+
else {
278+
res = sym_new_type(ctx, &PyLong_Type);
279+
}
236280
res = sym_new_type(ctx, &PyLong_Type);
237281
}
238282

Python/optimizer_cases.c.h

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

Tools/cases_generator/analyzer.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,6 @@ def has_error_without_pop(op: parser.CodeDef) -> bool:
635635
"_PyLong_IsNegative",
636636
"_PyLong_IsNonNegativeCompact",
637637
"_PyLong_IsZero",
638-
"_PyLong_Add",
639-
"_PyLong_Multiply",
640-
"_PyLong_Subtract",
641638
"_PyManagedDictPointer_IsValues",
642639
"_PyObject_GC_IS_SHARED",
643640
"_PyObject_GC_IS_TRACKED",

0 commit comments

Comments
 (0)