]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-115687: Most comparisons create Booleans, so propagate that information (GH-116360)
authorMark Shannon <mark@hotpy.org>
Wed, 6 Mar 2024 10:46:42 +0000 (10:46 +0000)
committerGitHub <noreply@github.com>
Wed, 6 Mar 2024 10:46:42 +0000 (10:46 +0000)
Most comparisons create booleans

Python/optimizer_bytecodes.c
Python/optimizer_cases.c.h

index ee67a2b075b0155f26ee52beef9fbe5ac4a9394c..07a1adb8cb8a783fffc9b5aee0a917693b7d3409 100644 (file)
@@ -351,6 +351,35 @@ dummy_func(void) {
         }
     }
 
+    op(_COMPARE_OP, (left, right -- res)) {
+        if (oparg & 16) {
+            OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
+        }
+        else {
+            OUT_OF_SPACE_IF_NULL(res = _Py_uop_sym_new_not_null(ctx));
+        }
+    }
+
+    op(_COMPARE_OP_INT, (left, right -- res)) {
+        OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
+    }
+
+    op(_COMPARE_OP_FLOAT, (left, right -- res)) {
+        OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
+    }
+
+    op(_COMPARE_OP_STR, (left, right -- res)) {
+        OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
+    }
+
+    op(_IS_OP, (left, right -- res)) {
+        OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
+    }
+
+    op(_CONTAINS_OP, (left, right -- res)) {
+        OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
+    }
+
     op(_LOAD_CONST, (-- value)) {
         // There should be no LOAD_CONST. It should be all
         // replaced by peephole_opt.
index 4ed1ac90c1e4bd931de6dc6f37ff9536225f9797..32dfca9c227116d28d7b9610356d12ff92dab23f 100644 (file)
         }
 
         case _COMPARE_OP: {
+            _Py_UopsSymbol *right;
+            _Py_UopsSymbol *left;
             _Py_UopsSymbol *res;
-            res = sym_new_unknown(ctx);
-            if (res == NULL) goto out_of_space;
+            right = stack_pointer[-1];
+            left = stack_pointer[-2];
+            if (oparg & 16) {
+                OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
+            }
+            else {
+                OUT_OF_SPACE_IF_NULL(res = _Py_uop_sym_new_not_null(ctx));
+            }
             stack_pointer[-2] = res;
             stack_pointer += -1;
             break;
         }
 
         case _COMPARE_OP_FLOAT: {
+            _Py_UopsSymbol *right;
+            _Py_UopsSymbol *left;
             _Py_UopsSymbol *res;
-            res = sym_new_unknown(ctx);
-            if (res == NULL) goto out_of_space;
+            right = stack_pointer[-1];
+            left = stack_pointer[-2];
+            OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
             stack_pointer[-2] = res;
             stack_pointer += -1;
             break;
         }
 
         case _COMPARE_OP_INT: {
+            _Py_UopsSymbol *right;
+            _Py_UopsSymbol *left;
             _Py_UopsSymbol *res;
-            res = sym_new_unknown(ctx);
-            if (res == NULL) goto out_of_space;
+            right = stack_pointer[-1];
+            left = stack_pointer[-2];
+            OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
             stack_pointer[-2] = res;
             stack_pointer += -1;
             break;
         }
 
         case _COMPARE_OP_STR: {
+            _Py_UopsSymbol *right;
+            _Py_UopsSymbol *left;
             _Py_UopsSymbol *res;
-            res = sym_new_unknown(ctx);
-            if (res == NULL) goto out_of_space;
+            right = stack_pointer[-1];
+            left = stack_pointer[-2];
+            OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
             stack_pointer[-2] = res;
             stack_pointer += -1;
             break;
         }
 
         case _IS_OP: {
-            _Py_UopsSymbol *b;
-            b = sym_new_unknown(ctx);
-            if (b == NULL) goto out_of_space;
-            stack_pointer[-2] = b;
+            _Py_UopsSymbol *right;
+            _Py_UopsSymbol *left;
+            _Py_UopsSymbol *res;
+            right = stack_pointer[-1];
+            left = stack_pointer[-2];
+            OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
+            stack_pointer[-2] = res;
             stack_pointer += -1;
             break;
         }
 
         case _CONTAINS_OP: {
-            _Py_UopsSymbol *b;
-            b = sym_new_unknown(ctx);
-            if (b == NULL) goto out_of_space;
-            stack_pointer[-2] = b;
+            _Py_UopsSymbol *right;
+            _Py_UopsSymbol *left;
+            _Py_UopsSymbol *res;
+            right = stack_pointer[-1];
+            left = stack_pointer[-2];
+            OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
+            stack_pointer[-2] = res;
             stack_pointer += -1;
             break;
         }