8000 gh-115685: Type/values propagate for TO_BOOL in tier 2 by Fidget-Spinner · Pull Request #115686 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-115685: Type/values propagate for TO_BOOL in tier 2 #115686

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

Merged
merged 16 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
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
Merge upstream changes
  • Loading branch information
Fidget-Spinner committed Feb 28, 2024
commit 4c9c97bbabbf7397afc44b34c0f1443a8a056afe
3 changes: 1 addition & 2 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -4042,8 +4042,7 @@ dummy_func(
tier2 pure op(_LOAD_CONST_INLINE_BORROW, (ptr/4 -- value)) {
value = ptr;
}
pure op (_POP_TOP_LOAD_CONST_INLINE_BORROW, (ptr/4, pop -- value)) {
TIER_TWO_ONLY;
tier2 pure op (_POP_TOP_LOAD_CONST_INLINE_BORROW, (ptr/4, pop -- value)) {
Py_DECREF(pop);
value = ptr;
}
Expand Down
1 change: 0 additions & 1 deletion Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions Python/optimizer_analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,6 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer,
} \
} while (0);

#define ERROR_IF(COND, LABEL) \
do { \
if (COND) { \
goto LABEL; \
} \
} while (0);

#define _LOAD_ATTR_NOT_NULL \
do { \
OUT_OF_SPACE_IF_NULL(attr = _Py_uop_sym_new_not_null(ctx)); \
Expand Down
46 changes: 30 additions & 16 deletions Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ dummy_func(void) {
assert(PyLong_CheckExact(sym_get_const(right)));
PyObject *temp = _PyLong_Add((PyLongObject *)sym_get_const(left),
(PyLongObject *)sym_get_const(right));
ERROR_IF(temp == NULL, error);
if (temp == NULL) {
goto error;
}
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
// TODO gh-115506:
// replace opcode with constant propagated one and add tests!
Expand All @@ -128,7 +130,9 @@ dummy_func(void) {
assert(PyLong_CheckExact(sym_get_const(right)));
PyObject *temp = _PyLong_Subtract((PyLongObject *)sym_get_const(left),
(PyLongObject *)sym_get_const(right));
ERROR_IF(temp == NULL, error);
if (temp == NULL) {
goto error;
}
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
// TODO gh-115506:
// replace opcode with constant propagated one and add tests!
Expand All @@ -144,7 +148,9 @@ dummy_func(void) {
assert(PyLong_CheckExact(sym_get_const(right)));
PyObject *temp = _PyLong_Multiply((PyLongObject *)sym_get_const(left),
(PyLongObject *)sym_get_const(right));
ERROR_IF(temp == NULL, error);
if (temp == NULL) {
goto error;
}
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
// TODO gh-115506:
// replace opcode with constant propagated one and add tests!
Expand All @@ -161,7 +167,9 @@ dummy_func(void) {
PyObject *temp = PyFloat_FromDouble(
PyFloat_AS_DOUBLE(sym_get_const(left)) +
PyFloat_AS_DOUBLE(sym_get_const(right)));
ERROR_IF(temp == NULL, error);
if (temp == NULL) {
goto error;
}
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
// TODO gh-115506:
// replace opcode with constant propagated one and update tests!
Expand All @@ -178,7 +186,9 @@ dummy_func(void) {
PyObject *temp = PyFloat_FromDouble(
PyFloat_AS_DOUBLE(sym_get_const(left)) -
PyFloat_AS_DOUBLE(sym_get_const(right)));
ERROR_IF(temp == NULL, error);
if (temp == NULL) {
goto error;
}
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
// TODO gh-115506:
// replace opcode with constant propagated one and update tests!
Expand All @@ -195,7 +205,9 @@ dummy_func(void) {
PyObject *temp = PyFloat_FromDouble(
PyFloat_AS_DOUBLE(sym_get_const(left)) *
PyFloat_AS_DOUBLE(sym_get_const(right)));
ERROR_IF(temp == NULL, error);
if (temp == NULL) {
goto error;
}
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
// TODO gh-115506:
// replace opcode with constant propagated one and update tests!
Expand All @@ -207,7 +219,7 @@ dummy_func(void) {

op(_TO_BOOL, (value -- res)) {
(void)value;
res = sym_new_known_type(ctx, &PyBool_Type);
res = sym_new_type(ctx, &PyBool_Type);
OUT_OF_SPACE_IF_NULL(res);
}

Expand All @@ -221,41 +233,41 @@ dummy_func(void) {
}

op(_TO_BOOL_INT, (value -- res)) {
sym_set_type(value, &PyLong_Type);
if (sym_is_const(value)) {
if (sym_is_const(value) && sym_matches_type(value, &PyLong_Type)) {
PyObject *load = _PyLong_IsZero((PyLongObject *)sym_get_const(value))
? Py_False : Py_True;
REPLACE_OP(this_instr, _POP_TOP_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)load);
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, load));
}
else {
OUT_OF_SPACE_IF_NULL(res = sym_new_known_type(ctx, &PyBool_Type));
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
}
sym_set_type(value, &PyLong_Type);
}

op(_TO_BOOL_LIST, (value -- res)) {
sym_set_type(value, &PyList_Type);
OUT_OF_SPACE_IF_NULL(res = sym_new_known_type(ctx, &PyBool_Type));
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
}

op(_TO_BOOL_NONE, (value -- res)) {
if (sym_is_const(value) && (sym_get_const(value) == Py_None)) {
if (sym_get_const(value) == Py_None) {
REPLACE_OP(this_instr, _POP_TOP_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)Py_False);
}
sym_set_const(value, Py_None);
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, Py_False));
}

op(_TO_BOOL_STR, (value -- res)) {
sym_set_type(value, &PyUnicode_Type);
if (sym_is_const(value)) {
if (sym_is_const(value) && sym_matches_type(value, &PyUnicode_Type)) {
PyObject *load = sym_get_const(value) == &_Py_STR(empty) ? Py_False : Py_True;
REPLACE_OP(this_instr, _POP_TOP_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)load);
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, load));
}
else {
OUT_OF_SPACE_IF_NULL(res = sym_new_known_type(ctx, &PyBool_Type));
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
}
sym_set_type(value, &PyUnicode_Type);
}

op(_LOAD_CONST, (-- value)) {
Expand Down Expand Up @@ -397,7 +409,9 @@ dummy_func(void) {
(void)callable;

PyFunctionObject *func = (PyFunctionObject *)(this_instr + 2)->operand;
ERROR_IF(func == NULL, error);
if (func == NULL) {
goto error;
}
PyCodeObject *co = (PyCodeObject *)func->func_code;

assert(self_or_null != NULL);
Expand Down
46 changes: 30 additions & 16 deletions Python/optimizer_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0