]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-131798: Optimize `_ITER_CHECK_TUPLE` (GH-134803)
authorNoam Cohen <noam@noam.me>
Tue, 27 May 2025 18:30:17 +0000 (21:30 +0300)
committerGitHub <noreply@github.com>
Tue, 27 May 2025 18:30:17 +0000 (02:30 +0800)
Misc/NEWS.d/next/Core_and_Builtins/2025-05-27-20-21-34.gh-issue-131798.b32zkl.rst [new file with mode: 0644]
Python/optimizer_bytecodes.c
Python/optimizer_cases.c.h

diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-05-27-20-21-34.gh-issue-131798.b32zkl.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-05-27-20-21-34.gh-issue-131798.b32zkl.rst
new file mode 100644 (file)
index 0000000..ed4b31b
--- /dev/null
@@ -0,0 +1 @@
+Allow the JIT to remove unnecessary ``_ITER_CHECK_TUPLE`` ops.
index 34250fd4385d3463a3cddd47dc8e8aa728dddeb2..e1209209660f920c0dadb528f4075acc04b9f587 100644 (file)
@@ -914,6 +914,13 @@ dummy_func(void) {
         }
     }
 
+    op(_ITER_CHECK_TUPLE, (iter, null_or_index -- iter, null_or_index)) {
+        if (sym_matches_type(iter, &PyTuple_Type)) {
+            REPLACE_OP(this_instr, _NOP, 0, 0);
+        }
+        sym_set_type(iter, &PyTuple_Type);
+    }
+
     op(_ITER_NEXT_RANGE, (iter, null_or_index -- iter, null_or_index, next)) {
        next = sym_new_type(ctx, &PyLong_Type);
     }
index bbd45067103679e4ed3aceffb834fa709629d5aa..db86edcc7859b5265422a4d854f5e87befbfe56f 100644 (file)
         }
 
         case _ITER_CHECK_TUPLE: {
+            JitOptSymbol *iter;
+            iter = stack_pointer[-2];
+            if (sym_matches_type(iter, &PyTuple_Type)) {
+                REPLACE_OP(this_instr, _NOP, 0, 0);
+            }
+            sym_set_type(iter, &PyTuple_Type);
             break;
         }