]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
fix branch tracing
authorKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Wed, 24 Sep 2025 10:55:11 +0000 (11:55 +0100)
committerKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Wed, 24 Sep 2025 10:55:11 +0000 (11:55 +0100)
Python/bytecodes.c
Python/generated_cases.c.h
Python/optimizer.c

index 658177c041dc6ea3678950e884c048f78db3d0d6..c30e314e653e82d99ed00d16072f06d7b9546e6c 100644 (file)
@@ -3059,7 +3059,7 @@ dummy_func(
             assert(PyStackRef_BoolCheck(cond));
             int flag = PyStackRef_IsFalse(cond);
             DEAD(cond);
-            RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
+            RECORD_JUMP_TAKEN();
             JUMPBY(flag ? oparg : next_instr->op.code == NOT_TAKEN);
         }
 
@@ -3067,7 +3067,7 @@ dummy_func(
             assert(PyStackRef_BoolCheck(cond));
             int flag = PyStackRef_IsTrue(cond);
             DEAD(cond);
-            RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
+            RECORD_JUMP_TAKEN();
             JUMPBY(flag ? oparg : next_instr->op.code == NOT_TAKEN);
         }
 
index 70e3b79856392072bd3b2082d16a8a9474b7d03f..83f5fde87e6a88d2a450f4e73b130b0a0c3ee9b4 100644 (file)
             (void)old_func;
             int _jump_taken = false;
             (void)_jump_taken;
-            _Py_CODEUNIT* const this_instr = next_instr;
-            (void)this_instr;
             frame->instr_ptr = next_instr;
             next_instr += 2;
             INSTRUCTION_STATS(POP_JUMP_IF_FALSE);
             cond = stack_pointer[-1];
             assert(PyStackRef_BoolCheck(cond));
             int flag = PyStackRef_IsFalse(cond);
-            RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
             JUMPBY(flag ? oparg : next_instr->op.code == NOT_TAKEN);
             stack_pointer += -1;
             assert(WITHIN_STACK_BOUNDS());
             (void)old_func;
             int _jump_taken = false;
             (void)_jump_taken;
-            _Py_CODEUNIT* const this_instr = next_instr;
-            (void)this_instr;
             frame->instr_ptr = next_instr;
             next_instr += 2;
             INSTRUCTION_STATS(POP_JUMP_IF_NONE);
                 cond = b;
                 assert(PyStackRef_BoolCheck(cond));
                 int flag = PyStackRef_IsTrue(cond);
-                RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
                 JUMPBY(flag ? oparg : next_instr->op.code == NOT_TAKEN);
             }
             stack_pointer += -1;
             (void)old_func;
             int _jump_taken = false;
             (void)_jump_taken;
-            _Py_CODEUNIT* const this_instr = next_instr;
-            (void)this_instr;
             frame->instr_ptr = next_instr;
             next_instr += 2;
             INSTRUCTION_STATS(POP_JUMP_IF_NOT_NONE);
                 cond = b;
                 assert(PyStackRef_BoolCheck(cond));
                 int flag = PyStackRef_IsFalse(cond);
-                RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
                 JUMPBY(flag ? oparg : next_instr->op.code == NOT_TAKEN);
             }
             stack_pointer += -1;
             (void)old_func;
             int _jump_taken = false;
             (void)_jump_taken;
-            _Py_CODEUNIT* const this_instr = next_instr;
-            (void)this_instr;
             frame->instr_ptr = next_instr;
             next_instr += 2;
             INSTRUCTION_STATS(POP_JUMP_IF_TRUE);
             cond = stack_pointer[-1];
             assert(PyStackRef_BoolCheck(cond));
             int flag = PyStackRef_IsTrue(cond);
-            RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
             JUMPBY(flag ? oparg : next_instr->op.code == NOT_TAKEN);
             stack_pointer += -1;
             assert(WITHIN_STACK_BOUNDS());
             cond = stack_pointer[-1];
             assert(PyStackRef_BoolCheck(cond));
             int flag = PyStackRef_IsFalse(cond);
-            RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
+            RECORD_JUMP_TAKEN();
             JUMPBY(flag ? oparg : next_instr->op.code == NOT_TAKEN);
             stack_pointer += -1;
             assert(WITHIN_STACK_BOUNDS());
                 cond = b;
                 assert(PyStackRef_BoolCheck(cond));
                 int flag = PyStackRef_IsTrue(cond);
-                RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
+                RECORD_JUMP_TAKEN();
                 JUMPBY(flag ? oparg : next_instr->op.code == NOT_TAKEN);
             }
             stack_pointer += -1;
                 cond = b;
                 assert(PyStackRef_BoolCheck(cond));
                 int flag = PyStackRef_IsFalse(cond);
-                RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
+                RECORD_JUMP_TAKEN();
                 JUMPBY(flag ? oparg : next_instr->op.code == NOT_TAKEN);
             }
             stack_pointer += -1;
             cond = stack_pointer[-1];
             assert(PyStackRef_BoolCheck(cond));
             int flag = PyStackRef_IsTrue(cond);
-            RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
+            RECORD_JUMP_TAKEN();
             JUMPBY(flag ? oparg : next_instr->op.code == NOT_TAKEN);
             stack_pointer += -1;
             assert(WITHIN_STACK_BOUNDS());
index c916ffd0e84e394bb095a7d83bb5653e5cbf08bd..b4d3429f7321fc46fd4339e1c569648a0f06033f 100644 (file)
@@ -671,9 +671,7 @@ _PyJIT_translate_single_bytecode_to_trace(
         case POP_JUMP_IF_TRUE:
         {
             RESERVE(1);
-            int counter = this_instr[1].cache;
-            int bitcount = counter & 1;
-            int jump_likely = bitcount;
+            int jump_likely = jump_taken;
             uint32_t uopcode = BRANCH_TO_GUARD[opcode - POP_JUMP_IF_FALSE][jump_likely];
             _Py_CODEUNIT *next_instr = target_instr + 1 + _PyOpcode_Caches[_PyOpcode_Deopt[opcode]];
             _Py_CODEUNIT *false_target = next_instr + oparg;