Skip to content

Commit 5f03d23

Browse files
Remove changes to JUMP_BACKWARD
1 parent 13ad45d commit 5f03d23

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3304,8 +3304,6 @@ def testfunc(n):
33043304

33053305
self.assertIn("_FOR_ITER_GEN_FRAME", uops)
33063306
self.assertIn("_YIELD_VALUE", uops)
3307-
# It's essential for performance that the trace loops around.
3308-
self.assertIn("_JUMP_TO_TOP", uops)
33093307
# _POP_TOP_NOP is a sign the optimizer ran and didn't hit bottom.
33103308
self.assertGreaterEqual(count_ops(ex, "_POP_TOP_NOP"), 3)
33113309

@@ -3331,8 +3329,6 @@ def testfunc(n):
33313329
self.assertIn("_FOR_ITER_GEN_FRAME", uops)
33323330
self.assertIn("_YIELD_VALUE", uops)
33333331
self.assertIn("_SEND_GEN_FRAME", uops)
3334-
# It's essential for performance that the trace loops around.
3335-
self.assertIn("_JUMP_TO_TOP", uops)
33363332
# _POP_TOP_NOP is a sign the optimizer ran and didn't hit bottom.
33373333
self.assertGreaterEqual(count_ops(ex, "_POP_TOP_NOP"), 2)
33383334

Python/optimizer.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -823,25 +823,16 @@ _PyJit_translate_single_bytecode_to_trace(
823823
_tstate->jit_tracer_state.initial_state.exit == NULL &&
824824
// These are coroutines, and we want to unroll those usually.
825825
opcode != JUMP_BACKWARD_NO_INTERRUPT) {
826-
// We encountered a second JUMP_BACKWARD but not to the top of our own loop.
826+
// We encountered a JUMP_BACKWARD but not to the top of our own loop.
827827
// We don't want to continue tracing as we might get stuck in the
828828
// inner loop. Instead, end the trace where the executor of the
829829
// inner loop might start and let the traces rejoin.
830-
if (_tstate->jit_tracer_state.translator_state.jump_backward_seen >= 1 ||
831-
// Also end the trace early if we probably have no more space left, as it's better
832-
// to link to another backwards jump trace.
833-
trace_length >= (_tstate->jit_tracer_state.prev_state.code_max_size / 3)) {
834-
OPT_STAT_INC(inner_loop);
835-
ADD_TO_TRACE(_EXIT_TRACE, 0, 0, target);
836-
trace[trace_length-1].operand1 = true; // is_control_flow
837-
DPRINTF(2, "JUMP_BACKWARD not to top ends trace %p %p %p\n", next_instr,
838-
_tstate->jit_tracer_state.initial_state.close_loop_instr, _tstate->jit_tracer_state.initial_state.start_instr);
839-
goto done;
840-
}
841-
else {
842-
assert(_tstate->jit_tracer_state.translator_state.jump_backward_seen == 0);
843-
_tstate->jit_tracer_state.translator_state.jump_backward_seen++;
844-
}
830+
OPT_STAT_INC(inner_loop);
831+
ADD_TO_TRACE(_EXIT_TRACE, 0, 0, target);
832+
trace[trace_length-1].operand1 = true; // is_control_flow
833+
DPRINTF(2, "JUMP_BACKWARD not to top ends trace %p %p %p\n", next_instr,
834+
_tstate->jit_tracer_state.initial_state.close_loop_instr, _tstate->jit_tracer_state.initial_state.start_instr);
835+
goto done;
845836
}
846837
break;
847838
}
@@ -1073,7 +1064,6 @@ _PyJit_TryInitializeTracing(
10731064
_tstate->jit_tracer_state.initial_state.exit = exit;
10741065
_tstate->jit_tracer_state.initial_state.stack_depth = curr_stackdepth;
10751066
_tstate->jit_tracer_state.initial_state.chain_depth = chain_depth;
1076-
_tstate->jit_tracer_state.translator_state.jump_backward_seen = 0;
10771067
_tstate->jit_tracer_state.prev_state.instr_frame = frame;
10781068
_tstate->jit_tracer_state.prev_state.dependencies_still_valid = true;
10791069
_tstate->jit_tracer_state.prev_state.instr_code = (PyCodeObject *)Py_NewRef(_PyFrame_GetCode(frame));

0 commit comments

Comments
 (0)