diff options
| author | Peter Lazorchak <lazorchakp@gmail.com> | 2024-02-16 18:02:48 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-16 18:02:48 (GMT) |
| commit | 13addd2bbdcbf96c5ea26a0f425c049f1b71e945 (patch) | |
| tree | 24bfa89bc472b02231e5a6d84a53fbe70f05bdae /Python/tier2_redundancy_eliminator_bytecodes.c | |
| parent | fbb016973149d983d30351bdd1aaf00df285c776 (diff) | |
| download | cpython-13addd2bbdcbf96c5ea26a0f425c049f1b71e945.zip cpython-13addd2bbdcbf96c5ea26a0f425c049f1b71e945.tar.gz cpython-13addd2bbdcbf96c5ea26a0f425c049f1b71e945.tar.bz2 | |
gh-115480: Type / constant propagation for float binary uops (GH-115550)
Co-authored-by: Ken Jin <kenjin@python.org>
Diffstat (limited to 'Python/tier2_redundancy_eliminator_bytecodes.c')
| -rw-r--r-- | Python/tier2_redundancy_eliminator_bytecodes.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/Python/tier2_redundancy_eliminator_bytecodes.c b/Python/tier2_redundancy_eliminator_bytecodes.c index 6aae590..3f6e8ce 100644 --- a/Python/tier2_redundancy_eliminator_bytecodes.c +++ b/Python/tier2_redundancy_eliminator_bytecodes.c @@ -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. |
