diff options
author | Brandt Bucher <brandtbucher@microsoft.com> | 2025-04-01 22:10:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-01 22:10:15 (GMT) |
commit | 1a9d4a1fb3d4beda7c7e8483af7c6bc7ac477e9f (patch) | |
tree | 49680ffa71a7d842ae94c40fa45c2c436d9691c5 /Python/optimizer_bytecodes.c | |
parent | cd69d55f64087f74da816eaf20c34ddeabfdb2bb (diff) | |
download | cpython-1a9d4a1fb3d4beda7c7e8483af7c6bc7ac477e9f.zip cpython-1a9d4a1fb3d4beda7c7e8483af7c6bc7ac477e9f.tar.gz cpython-1a9d4a1fb3d4beda7c7e8483af7c6bc7ac477e9f.tar.bz2 |
GH-131798: Allow the JIT to remove more int/float/str guards (GH-131800)
Diffstat (limited to 'Python/optimizer_bytecodes.c')
-rw-r--r-- | Python/optimizer_bytecodes.c | 61 |
1 files changed, 25 insertions, 36 deletions
diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c index 163a8bf..a948ccc 100644 --- a/Python/optimizer_bytecodes.c +++ b/Python/optimizer_bytecodes.c @@ -104,22 +104,18 @@ dummy_func(void) { res = sym_new_null(ctx); } - op(_GUARD_BOTH_INT, (left, right -- left, right)) { - if (sym_matches_type(left, &PyLong_Type)) { - if (sym_matches_type(right, &PyLong_Type)) { - REPLACE_OP(this_instr, _NOP, 0, 0); - } - else { - REPLACE_OP(this_instr, _GUARD_TOS_INT, 0, 0); - } + op(_GUARD_TOS_INT, (tos -- tos)) { + if (sym_matches_type(tos, &PyLong_Type)) { + REPLACE_OP(this_instr, _NOP, 0, 0); } - else { - if (sym_matches_type(right, &PyLong_Type)) { - REPLACE_OP(this_instr, _GUARD_NOS_INT, 0, 0); - } + sym_set_type(tos, &PyLong_Type); + } + + op(_GUARD_NOS_INT, (nos, unused -- nos, unused)) { + if (sym_matches_type(nos, &PyLong_Type)) { + REPLACE_OP(this_instr, _NOP, 0, 0); } - sym_set_type(left, &PyLong_Type); - sym_set_type(right, &PyLong_Type); + sym_set_type(nos, &PyLong_Type); } op(_GUARD_TYPE_VERSION, (type_version/2, owner -- owner)) { @@ -145,32 +141,18 @@ dummy_func(void) { } } - op(_GUARD_BOTH_FLOAT, (left, right -- left, right)) { - if (sym_matches_type(left, &PyFloat_Type)) { - if (sym_matches_type(right, &PyFloat_Type)) { - REPLACE_OP(this_instr, _NOP, 0, 0); - } - else { - REPLACE_OP(this_instr, _GUARD_TOS_FLOAT, 0, 0); - } - } - else { - if (sym_matches_type(right, &PyFloat_Type)) { - REPLACE_OP(this_instr, _GUARD_NOS_FLOAT, 0, 0); - } + op(_GUARD_TOS_FLOAT, (tos -- tos)) { + if (sym_matches_type(tos, &PyFloat_Type)) { + REPLACE_OP(this_instr, _NOP, 0, 0); } - - sym_set_type(left, &PyFloat_Type); - sym_set_type(right, &PyFloat_Type); + sym_set_type(tos, &PyFloat_Type); } - op(_GUARD_BOTH_UNICODE, (left, right -- left, right)) { - if (sym_matches_type(left, &PyUnicode_Type) && - sym_matches_type(right, &PyUnicode_Type)) { - REPLACE_OP(this_instr, _NOP, 0 ,0); + op(_GUARD_NOS_FLOAT, (nos, unused -- nos, unused)) { + if (sym_matches_type(nos, &PyFloat_Type)) { + REPLACE_OP(this_instr, _NOP, 0, 0); } - sym_set_type(left, &PyUnicode_Type); - sym_set_type(right, &PyUnicode_Type); + sym_set_type(nos, &PyFloat_Type); } op(_BINARY_OP, (left, right -- res)) { @@ -418,6 +400,13 @@ dummy_func(void) { } } + op(_GUARD_NOS_UNICODE, (nos, unused -- nos, unused)) { + if (sym_matches_type(nos, &PyUnicode_Type)) { + REPLACE_OP(this_instr, _NOP, 0, 0); + } + sym_set_type(nos, &PyUnicode_Type); + } + op(_GUARD_TOS_UNICODE, (value -- value)) { if (sym_matches_type(value, &PyUnicode_Type)) { REPLACE_OP(this_instr, _NOP, 0, 0); |