mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-115480: Type / constant propagation for float binary uops (GH-115550)
Co-authored-by: Ken Jin <kenjin@python.org>
This commit is contained in:
parent
fbb0169731
commit
13addd2bbd
3 changed files with 184 additions and 38 deletions
|
@ -132,6 +132,63 @@ dummy_func(void) {
|
|||
}
|
||||
}
|
||||
|
||||
op(_BINARY_OP_ADD_FLOAT, (left, right -- res)) {
|
||||
if (is_const(left) && is_const(right)) {
|
||||
assert(PyFloat_CheckExact(get_const(left)));
|
||||
assert(PyFloat_CheckExact(get_const(right)));
|
||||
PyObject *temp = PyFloat_FromDouble(
|
||||
PyFloat_AS_DOUBLE(get_const(left)) +
|
||||
PyFloat_AS_DOUBLE(get_const(right)));
|
||||
if (temp == NULL) {
|
||||
goto error;
|
||||
}
|
||||
res = sym_new_const(ctx, temp);
|
||||
// TODO gh-115506:
|
||||
// replace opcode with constant propagated one and update tests!
|
||||
}
|
||||
else {
|
||||
OUT_OF_SPACE_IF_NULL(res = sym_new_known_type(ctx, &PyFloat_Type));
|
||||
}
|
||||
}
|
||||
|
||||
op(_BINARY_OP_SUBTRACT_FLOAT, (left, right -- res)) {
|
||||
if (is_const(left) && is_const(right)) {
|
||||
assert(PyFloat_CheckExact(get_const(left)));
|
||||
assert(PyFloat_CheckExact(get_const(right)));
|
||||
PyObject *temp = PyFloat_FromDouble(
|
||||
PyFloat_AS_DOUBLE(get_const(left)) -
|
||||
PyFloat_AS_DOUBLE(get_const(right)));
|
||||
if (temp == NULL) {
|
||||
goto error;
|
||||
}
|
||||
res = sym_new_const(ctx, temp);
|
||||
// TODO gh-115506:
|
||||
// replace opcode with constant propagated one and update tests!
|
||||
}
|
||||
else {
|
||||
OUT_OF_SPACE_IF_NULL(res = sym_new_known_type(ctx, &PyFloat_Type));
|
||||
}
|
||||
}
|
||||
|
||||
op(_BINARY_OP_MULTIPLY_FLOAT, (left, right -- res)) {
|
||||
if (is_const(left) && is_const(right)) {
|
||||
assert(PyFloat_CheckExact(get_const(left)));
|
||||
assert(PyFloat_CheckExact(get_const(right)));
|
||||
PyObject *temp = PyFloat_FromDouble(
|
||||
PyFloat_AS_DOUBLE(get_const(left)) *
|
||||
PyFloat_AS_DOUBLE(get_const(right)));
|
||||
if (temp == NULL) {
|
||||
goto error;
|
||||
}
|
||||
res = sym_new_const(ctx, temp);
|
||||
// TODO gh-115506:
|
||||
// replace opcode with constant propagated one and update tests!
|
||||
}
|
||||
else {
|
||||
OUT_OF_SPACE_IF_NULL(res = sym_new_known_type(ctx, &PyFloat_Type));
|
||||
}
|
||||
}
|
||||
|
||||
op(_LOAD_CONST, (-- value)) {
|
||||
// There should be no LOAD_CONST. It should be all
|
||||
// replaced by peephole_opt.
|
||||
|
|
66
Python/tier2_redundancy_eliminator_cases.c.h
generated
66
Python/tier2_redundancy_eliminator_cases.c.h
generated
|
@ -270,27 +270,81 @@
|
|||
}
|
||||
|
||||
case _BINARY_OP_MULTIPLY_FLOAT: {
|
||||
_Py_UOpsSymType *right;
|
||||
_Py_UOpsSymType *left;
|
||||
_Py_UOpsSymType *res;
|
||||
res = sym_new_unknown(ctx);
|
||||
if (res == NULL) goto out_of_space;
|
||||
right = stack_pointer[-1];
|
||||
left = stack_pointer[-2];
|
||||
if (is_const(left) && is_const(right)) {
|
||||
assert(PyFloat_CheckExact(get_const(left)));
|
||||
assert(PyFloat_CheckExact(get_const(right)));
|
||||
PyObject *temp = PyFloat_FromDouble(
|
||||
PyFloat_AS_DOUBLE(get_const(left)) *
|
||||
PyFloat_AS_DOUBLE(get_const(right)));
|
||||
if (temp == NULL) {
|
||||
goto error;
|
||||
}
|
||||
res = sym_new_const(ctx, temp);
|
||||
// TODO gh-115506:
|
||||
// replace opcode with constant propagated one and update tests!
|
||||
}
|
||||
else {
|
||||
OUT_OF_SPACE_IF_NULL(res = sym_new_known_type(ctx, &PyFloat_Type));
|
||||
}
|
||||
stack_pointer[-2] = res;
|
||||
stack_pointer += -1;
|
||||
break;
|
||||
}
|
||||
|
||||
case _BINARY_OP_ADD_FLOAT: {
|
||||
_Py_UOpsSymType *right;
|
||||
_Py_UOpsSymType *left;
|
||||
_Py_UOpsSymType *res;
|
||||
res = sym_new_unknown(ctx);
|
||||
if (res == NULL) goto out_of_space;
|
||||
right = stack_pointer[-1];
|
||||
left = stack_pointer[-2];
|
||||
if (is_const(left) && is_const(right)) {
|
||||
assert(PyFloat_CheckExact(get_const(left)));
|
||||
assert(PyFloat_CheckExact(get_const(right)));
|
||||
PyObject *temp = PyFloat_FromDouble(
|
||||
PyFloat_AS_DOUBLE(get_const(left)) +
|
||||
PyFloat_AS_DOUBLE(get_const(right)));
|
||||
if (temp == NULL) {
|
||||
goto error;
|
||||
}
|
||||
res = sym_new_const(ctx, temp);
|
||||
// TODO gh-115506:
|
||||
// replace opcode with constant propagated one and update tests!
|
||||
}
|
||||
else {
|
||||
OUT_OF_SPACE_IF_NULL(res = sym_new_known_type(ctx, &PyFloat_Type));
|
||||
}
|
||||
stack_pointer[-2] = res;
|
||||
stack_pointer += -1;
|
||||
break;
|
||||
}
|
||||
|
||||
case _BINARY_OP_SUBTRACT_FLOAT: {
|
||||
_Py_UOpsSymType *right;
|
||||
_Py_UOpsSymType *left;
|
||||
_Py_UOpsSymType *res;
|
||||
res = sym_new_unknown(ctx);
|
||||
if (res == NULL) goto out_of_space;
|
||||
right = stack_pointer[-1];
|
||||
left = stack_pointer[-2];
|
||||
if (is_const(left) && is_const(right)) {
|
||||
assert(PyFloat_CheckExact(get_const(left)));
|
||||
assert(PyFloat_CheckExact(get_const(right)));
|
||||
PyObject *temp = PyFloat_FromDouble(
|
||||
PyFloat_AS_DOUBLE(get_const(left)) -
|
||||
PyFloat_AS_DOUBLE(get_const(right)));
|
||||
if (temp == NULL) {
|
||||
goto error;
|
||||
}
|
||||
res = sym_new_const(ctx, temp);
|
||||
// TODO gh-115506:
|
||||
// replace opcode with constant propagated one and update tests!
|
||||
}
|
||||
else {
|
||||
OUT_OF_SPACE_IF_NULL(res = sym_new_known_type(ctx, &PyFloat_Type));
|
||||
}
|
||||
stack_pointer[-2] = res;
|
||||
stack_pointer += -1;
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue