aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python
diff options
context:
space:
mode:
authorNoam Cohen <noam@noam.me>2025-06-09 13:33:18 +0300
committerGitHub <noreply@github.com>2025-06-09 18:33:18 +0800
commitb150b6aca7b17efe1bb13c3058d61cdefb83237e (patch)
tree17a9dec39d71e6f543c1b6f5ae83a3ee3b4cfc7d /Python
parentc19e36cc4eabacaacc359e8b2550b10c2965a31a (diff)
downloadcpython-b150b6aca7b17efe1bb13c3058d61cdefb83237e.tar.gz
cpython-b150b6aca7b17efe1bb13c3058d61cdefb83237e.zip
gh-131798: Optimize `_UNARY_INVERT` (GH-135222)
Diffstat (limited to 'Python')
-rw-r--r--Python/optimizer_bytecodes.c9
-rw-r--r--Python/optimizer_cases.c.h9
2 files changed, 17 insertions, 1 deletions
diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c
index fbf4dfd3db6..a9d5e92ca02 100644
--- a/Python/optimizer_bytecodes.c
+++ b/Python/optimizer_bytecodes.c
@@ -467,6 +467,15 @@ dummy_func(void) {
res = sym_new_truthiness(ctx, value, false);
}
+ op(_UNARY_INVERT, (value -- res)) {
+ if (sym_matches_type(value, &PyLong_Type)) {
+ res = sym_new_type(ctx, &PyLong_Type);
+ }
+ else {
+ res = sym_new_not_null(ctx);
+ }
+ }
+
op(_COMPARE_OP, (left, right -- res)) {
if (oparg & 16) {
res = sym_new_type(ctx, &PyBool_Type);
diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h
index b42f47c75ea..4780e492f61 100644
--- a/Python/optimizer_cases.c.h
+++ b/Python/optimizer_cases.c.h
@@ -285,8 +285,15 @@
}
case _UNARY_INVERT: {
+ JitOptSymbol *value;
JitOptSymbol *res;
- res = sym_new_not_null(ctx);
+ value = stack_pointer[-1];
+ if (sym_matches_type(value, &PyLong_Type)) {
+ res = sym_new_type(ctx, &PyLong_Type);
+ }
+ else {
+ res = sym_new_not_null(ctx);
+ }
stack_pointer[-1] = res;
break;
}