From 6b00b12d6a73a46ee0603dfc71d0203813659ad1 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Fri, 19 Apr 2024 09:28:54 +0100 Subject: [PATCH 1/2] Move SET_IP from the main trace to error stubs where possible. --- Python/bytecodes.c | 3 ++- Python/executor_cases.c.h | 2 ++ Python/optimizer.c | 1 + Python/optimizer_analysis.c | 3 --- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Python/bytecodes.c b/Python/bytecodes.c index d6fb66a7be34ac..7a5e7ecfe90185 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -4201,7 +4201,8 @@ dummy_func( EXIT_TO_TRACE(); } - tier2 op(_ERROR_POP_N, (unused[oparg] --)) { + tier2 op(_ERROR_POP_N, (target/2, unused[oparg] --)) { + frame->instr_ptr = ((_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive) + target; SYNC_SP(); GOTO_UNWIND(); } diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index a3447da00477ca..2f4449239b1279 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -4168,6 +4168,8 @@ case _ERROR_POP_N: { oparg = CURRENT_OPARG(); + uint32_t target = (uint32_t)CURRENT_OPERAND(); + frame->instr_ptr = ((_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive) + target; stack_pointer += -oparg; GOTO_UNWIND(); break; diff --git a/Python/optimizer.c b/Python/optimizer.c index 5c69d9d5de92eb..b53cd78c7bb104 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -971,6 +971,7 @@ prepare_for_execution(_PyUOpInstruction *buffer, int length) current_error_target = target; make_exit(&buffer[next_spare], _ERROR_POP_N, 0); buffer[next_spare].oparg = popped; + buffer[next_spare].operand = target; next_spare++; } buffer[i].error_target = current_error; diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c index 90444e33568b9d..111f2c56a4074e 100644 --- a/Python/optimizer_analysis.c +++ b/Python/optimizer_analysis.c @@ -548,9 +548,6 @@ remove_unneeded_uops(_PyUOpInstruction *buffer, int buffer_size) needs_ip = true; may_have_escaped = true; } - if (_PyUop_Flags[opcode] & HAS_ERROR_FLAG) { - needs_ip = true; - } if (needs_ip && last_set_ip >= 0) { if (buffer[last_set_ip].opcode == _CHECK_VALIDITY) { buffer[last_set_ip].opcode = _CHECK_VALIDITY_AND_SET_IP; From 75acbe142ea59f248d0da4716e4258d9673fb591 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Fri, 19 Apr 2024 10:31:28 +0100 Subject: [PATCH 2/2] Fix test --- Lib/test/test_capi/test_opt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_capi/test_opt.py b/Lib/test/test_capi/test_opt.py index 28d18739b6d4a5..7caa3d64a68fc2 100644 --- a/Lib/test/test_capi/test_opt.py +++ b/Lib/test/test_capi/test_opt.py @@ -231,7 +231,7 @@ def testfunc(x): ex = get_first_executor(testfunc) self.assertIsNotNone(ex) uops = get_opnames(ex) - self.assertIn("_SET_IP", uops) + self.assertIn("_JUMP_TO_TOP", uops) self.assertIn("_LOAD_FAST_0", uops) def test_extended_arg(self):