From 57f417e91bd3278fcec090a026f0168408408317 Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Wed, 24 Sep 2025 11:55:11 +0100 Subject: [PATCH] fix branch tracing --- Python/bytecodes.c | 4 ++-- Python/generated_cases.c.h | 20 ++++---------------- Python/optimizer.c | 4 +--- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 658177c041dc..c30e314e653e 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -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); } diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 70e3b7985639..83f5fde87e6a 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -11024,8 +11024,6 @@ (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); @@ -11034,7 +11032,6 @@ 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()); @@ -11052,8 +11049,6 @@ (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); @@ -11082,7 +11077,6 @@ 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; @@ -11101,8 +11095,6 @@ (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); @@ -11131,7 +11123,6 @@ 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; @@ -11150,8 +11141,6 @@ (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); @@ -11160,7 +11149,6 @@ 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()); @@ -24811,7 +24799,7 @@ 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()); @@ -24860,7 +24848,7 @@ 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; @@ -24910,7 +24898,7 @@ 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; @@ -24940,7 +24928,7 @@ 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()); diff --git a/Python/optimizer.c b/Python/optimizer.c index c916ffd0e84e..b4d3429f7321 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -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; -- 2.47.3